Scala code compiles to the Java bytecode and runs on the JVM (Java Virtual Machine). As the name suggests, the JVM was not built specifically for Scala. Because of this, there is a mismatch between what is expressible with the Scala language and what the JVM supports. The consequences are twofold:
- The compiler converts Scala features that are not supported by the JVM into the proper bytecode, mostly by creating wrapper classes. As a result, the compilation of a simple Scala program might lead to the creation of dozens or hundreds of classes, which in turn leads to decreased performance and a higher garbage footprint. These negative consequences, in essence, are just an implementation detail. As the JVM improves, it ...