Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Trickiness" to calling Scala code from Java?

There is a Scala library (that only exists written in Scala) that I really want to use in my Java app. I am trying to evaluate whether I can do this or not without suffering any hidden gotchyas/caveats/pitfalls. So I went straight to the Scala FAQ, where they answer this very question (well, sort of):

Accessing Java classes from Scala code is no problem at all. Using a Scala class from Java can get tricky, in particular if your Scala class uses advanced features like generics, polymorphic methods, or abstract types.

I then found several other sites (such as this one) that seem to indicate there is no problem in calling Scala from inside Java, as it is all compiled JVM bytecode.

So I have two very conflicting sources of information, and I'm stuck in the middle trying to determine what use cases make calling Scala from Java "tricky", and which use cases are straight forward. Any ideas?

like image 821
smeeb Avatar asked Sep 29 '22 20:09

smeeb


1 Answers

If the scala library you are calling uses "tricky" features, I suppose you could wrap it (in scala) in a manner such that the wrapper does not expose any of the "tricky" features to calling code.

like image 167
Arleigh Avatar answered Oct 10 '22 12:10

Arleigh