本文介绍了Scala炸弹? (像拉链炸弹)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅滑稽的标题,我使用它类似于。是否可以创建一个scala源文件,这将在编译时产生大量的类文件(或一个非常大的单个类文件)?是否有任何方法类文件的大小可以比源文件的大小线性增长更快?

Please excuse the funny title, I am using it in analogy with "zip bomb". Is it possible to create a scala source file, that will, when compiled, produce a large number of class files (or a very large single class file)? Is there any way the size of the class files could grow faster than linearly with the size of the source file?

推荐答案

class Huge[@specialized A, @specialized B, @specialized C](
  val a: A, val b: B, val c: C
) {} // 730 files, 2.9 MB

class Gigantic[@specialized A, @specialized B, @specialized C, @specialized D](
  val a: A, val b: B, val c: C, val d: D
) {} // 6562 files, 26 MB

模式匹配也可能涉及大量的复杂情况下的代码重复(尽管我发现很难预测将发生)。

Pattern matching can also involve a lot of code duplication for complex cases (though I find it difficult to predict exactly when this will occur).

这篇关于Scala炸弹? (像拉链炸弹)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 13:44