问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/25895759/trickiness-to-calling-scala-code-from-java