irfan khan
irfan khan

Reputation: 45

why does scala generate too much class files after compilation?

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

Answers (1)

Odomontois
Odomontois

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:

  1. A .class for each lambda expression
  2. A .class for each object and package object
  3. A .class for each trait with implemented methods
  4. A .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

Related Questions