Chapter 10. Integrating Scala with Java

 

In this chapter

  • The benefits of using interfaces for Scala-Java interaction
  • The dangers of automatic implicit conversions of Java types
  • The complications of Java serialization in Scala
  • How to effectively use annotations in Scala for Java libraries

One of the biggest advantages of the Scala language is its ability to seamlessly interact with existing Java libraries and applications. Although this interaction isn’t completely seamless, Scala offers the tightest integration to Java of any JVM language.

The key to knowing how to integrate Scala and Java lies in the Java Virtual Machine specification and how each language encodes onto that specification. Scala does its best to translate simple language features directly onto JVM features. But complicated Scala features are implemented with some compiler tricks, and these tricks are usually the cause of issues when integrating with Java. For the most part, the Java language translates simply into JVM bytecode; however, it too has language features that use compiler tricks. These will also cause rough spots in Scala/ Java interaction.

10.1. The language mismatch between Scala and Java

10.2. Be wary of implicit conversions

10.3. Be wary of Java serialization

10.4. Annotate your annotations

10.5. Summary

sitemap