Reputation: 45
I am working in Scala project, and after writing and compiling Scala code, i saw couple of class files in my destination folder. I am curious to know why does it create too much class files? Is there any specific reason?
Upvotes: 0
Views: 362
Reputation: 16318
Scala compiler is definitely creating a lot of additional modules to make it's way to jvm representation. For example in version 2.11 it creates:
.class
for each lambda expression.class
for each object
and package object
.class
for each trait
with implemented methodsA .class
for each specialization, for example in
class Foo[@specialized(Long, Double) A, @specialized(Long, Double) B]
it will create 3 * 3 = 9 different classes for all (Long, Double, AnyRef)
x (Long Double, AnyRef)
combinations.
But these problems are definitely under fix theese days.
Scala 2.12 in exchange to jdk 8
requirement is dropping 1 and 3 overhead, because of SAM
lambda representations and interface default methods.
Dotty's Linker has autospecialization feature which will only generate needed specialization for you code and is greatly reducing troubles with 4.
Upvotes: 9