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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Specialization is inherently exponential in the number of type parameters specialized.
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).