Introduction

In general, the ability to easily mix Scala and Java code is pretty seamless and amazing. In most cases, you can create an SBT project, put your Scala code in src/main/scala, put your Java code in src/main/java, and it “just works.” For instance, the recipes on web services in Chapter 15 provide many examples of calling existing Java libraries from Scala code.

In my Scala/Java interactions, the biggest issues I’ve run into deal with the differences between their collections libraries. However, I’ve always been able to work through those problems with Scala’s JavaConversions object.

If you’re going to be accessing Scala code from Java, the other problem you can run into is that there are things you can do in Scala that don’t map well to Java. If you’re going to use Scala features like implicit conversions and parameters, currying, traits that have implemented methods, and other advanced features, you’ll want to keep that Scala code away from your public API.

Finally, for some cases such as serialization, methods with varargs parameters, and creating JavaBean-like classes in Scala, it’s important to know the annotations that are available to you.

Get Scala Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.