Question on scala VS java

I tried to write some real production programs, they require a lot of the third party libraries. I searched and found most of the libraries are Java wrappers. So my question:

  1. Does java wrappers have performance loss?
  2. Can the data structure such as List be shared between Java and scala?
  3. Since a lot of libraries such as MQ, storage are just Java, why don’t dev with Java directly?

Thank you.

Java interop is a high priority and must be considered a success.

Most Scala JVM code uses Java SE libraries to some extent.

Consider doobie as a layer that makes a legacy API less uncomfortable.

1 Like

For collections, see Scala Standard Library 2.13.8 - scala.collection.JavaConverters. Overhead is negligible since the collection isn’t copied (in either direction).

It’s quite common to use Java libraries directly from Scala, even if nobody has made a special Scala facade for the library. Having such a facade can make the API more pleasant and idiomatic from the Scala side, but such facades aren’t strictly necessary to have.


If it’s a question of Team Scala vs Java core developers meeting on the pitch, or wherever these contests usually take place, then Team Scala could definitely take them due to their enduring youth and vigor. Martin Odersky obviously keeps himself in great shape. They might have to bring back Adriaan Moors. John De Goes volunteered to sponsor a ticket, so he might be eligible to compete. Alumni of the team remain remarkably well-preserved while at EPFL, but have a kind of Dorian Gray moment when they leave for Google. Presumably this is because they are no longer running up and down the famous staircase every day, which is excellent physical conditioning.


Great answers already just let me add a couple of points.

There is an overhead for the wrapping / unwrapping but it shouldn’t be something significant.

Technically speaking yes, at the end of the day all the code is running in the same JVM. However, in practice, is weird that a Java library could accept Scala collections… since that would mean they are actually Scala libraries.
Nevertheless, as Seth pointed out, the Scala standard library provides us with ways to “disguise” Scala collections as Java ones (and vice versa) thus the interoperation is usually easy.

Well because those people are Scala developers who want to write Scala but need to use that Java library, and since the interoperation is easy enough (and for you as an end-user there is probably already a wrapper out there) there is no need to consider using Java.
Now, this question is basically why use Scala at all and there are multiple ways to answer that, but you probably already have your favorite answer.