Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use java 8 in an mixed scala 2.10 / java project built by sbt?

To what degree can I use java 8 in a mixed java / scala 2.10 sbt project?
Can I emit java 8 bytecode? Use java 8 language features? Or are there features in scala 2.11 that are necessary? Is there an interop story?

like image 478
Josh Marcus Avatar asked Aug 20 '15 19:08

Josh Marcus


People also ask

Which Java version does sbt use?

sbt is a build tool for Scala, Java, and more. It requires Java 1.8 or later.

What version of Scala does sbt use?

However, this SBT version only supports Scala 2.12.

Is Scala compatible with Java?

Scala is compiled to Java bytecodes, and you can use tools like javap (Java class file disassembler) to disassemble bytecodes generated by the Scala compiler. In most cases, Scala features are translated to Java features so that Scala can easily integrate with Java.

Why is Scala compatible with Java?

Scala is a statically typed language that is based on Java. Thus, anyone who's well-versed with Java's syntax will find it pretty easy to learn Scala.


1 Answers

From the 2.10.4 Scala release notes:

New ByteCode emitter based on ASM

Can target JDK 1.5, 1.6 and 1.7

Emits 1.6 bytecode by default

Old 1.5 backend is deprecated

Also

The official Scala 2.12 distribution will be built for Java 8 (and thus require it).

More background info of when you can expect to fully use Java 8:

The Scala 2.11.x series targets Java 6, with (evolving) experimental >support for Java 8. In 2.11.1, Java 8 support is mostly limited to reading >Java 8 bytecode and parsing Java 8 source. Stay tuned for more complete >(experimental) Java 8 support. The next major release, 2.12, will most >likely target Java 8 by default.

And...

Planned future Java 8-centric additions for Scala 2.12 include Java 8 >style closures, which will allow the Scala compiler to emit closure >classes (lambdas) just as you can with Java 8. There’s also planned lambda >syntax for SAM types. Again, in Java 8 fashion, this lets you instantiate >any type with one single abstract method by passing a lambda, improving >the user experiences for libraries written for Java 8 in Scala.

like image 71
M.K. Avatar answered Sep 27 '22 16:09

M.K.