Paul Krill
Editor at Large

Scala upgrade brings closer alignment with Java 8

news
Nov 4, 20162 mins

Scala 2.12 has an overhauled compiler to better use the VM features of Java 8

alignment balls
Credit: Andrew Malone

Scala, a trendy object-oriented and functional language for the Java Virtual Machine, is now aligned with Java 8, the latest release of the standard Java platform.

Version 2.12.0, released Wednesday, features a complete overhaul of its compiler to take advantage of VM features in the Java upgrade, according to scala-lang.org. With Scala 2.12.0, a trait compiles directly to an interface with default methods, to improve binary compatibility and Java interoperability. And with Java 8 allowing concrete methods in interfaces, Scala 2.12.0 is able to compile a trait to a single interface classfile.

“Before, a trait was represented as an interface and a class that held the method implementations,” scala-lang.org said. “Scala 2.12 is all about making optimal use of Java 8’s new features—and thus generates code that requires a Java 8 runtime.”

Additionally, Scala and Java 8 interop has been improved for functional code, with methods that take functions easily called in each direction via lambda syntax. “The FunctionN classes in Scala’s standard library are now SAM (Single Abstract Method) types and all SAM types are treated uniformly—from type-checking until code generation—no class file is generated for lambdas, and invokedynamic is used instead.”

The new version also features a new bytecode optimizer. “The optimizer is configured using the -opt compiler option. By default it only removes unreachable code within a method.” Dead code elimination and a number of cleanup optimizations are included as well.

Version 2.12.0 standardizes on the GenBCode back end to emit code more quickly, and the interactive shell in Scala has been improved. It also has an upgraded type inference for Scala.js, which generates JavaScript from Scala.

Scala 2.12.1, which will rectify some issues with release 2.12.0, is coming later this month; scala-lang.org says it will clean up code and offer front-end fixes. A future release of Scala 2.12.x will address an issue in which parallel collections are prone to deadlock in the REPL and object initializers. From here on out, Scala 2.12.x releases will be fully binary compatible.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author