Java RMI with Scala, is this possible?
Asked Answered
A

3

7

Java RMI -Remote Method Invocation- is Java to Java only.

On the Scala website I read that the integration with Java is seamless and that:

Scala programs run on the Java VM, are byte code compatible with Java so you can make full use of existing Java libraries or existing application code. You can call Scala from Java and you can call Java from Scala, the integration is seamless.

Does this mean that I can successfully use a Java to Scala RMI?

Did anyone experiment this first-hand?

EDIT:

Any known or discovered gotchas??

Ashjian answered 20/7, 2011 at 14:48 Comment(0)
G
5

Yes, here's a link to a message thread where it looks like somebody's done it. It says:

Yes it can! Thanks for help. I now have a little RMI-based pair of Scala programs that will be performing transfers of documents from one Documentum system to another (of a previous version); the Scala code is interacting very nicely with the Documentum Java libraries.

Figuring out how to get the method signatures to include throws RemoteException seems to have been the biggest hurdle.

Gerrit answered 20/7, 2011 at 14:57 Comment(0)
B
1

Yes, this can be done. The rmi compiler works with java byte code, so the language used really doesn't matter. I've done this for a class project.

Buenabuenaventura answered 20/7, 2011 at 15:4 Comment(3)
thanks! i'm not familiar with Scala; are there any possible issues related to using two different languages or anything else that I should be aware of? What about collections conversion types for instance?Ashjian
There are conversion methods between scala list and java lists (and other data structures) in the scala library, so that's not an issue.Buenabuenaventura
rmic is deprecated since Java 1.5, so practically for ages.Semeiology
T
0

It would depend on what RMI library you are using but in general, the answer is "Yes." Although, note that if you write a method that returns (for example) a Scala collection like scala.collections.immutable.List, then your calling Java code will probably not be able to convert that to a java.util.List.

Toolmaker answered 20/7, 2011 at 14:52 Comment(2)
i'm not familiar with Scala at all, why do you think there would we conversion issues between the two List types?Ashjian
You can see this question for more details: #2430444 . Basically, the scala.collections.immutable.List is immutable (cannot be changed) while java.util.List is usually not expected to be immutable.Toolmaker

© 2022 - 2024 — McMap. All rights reserved.