Reputation: 188
I cannot reference Scala classes from Java code when using Eclipse IDE. The Scala class in question is nested within a Scala-object structure. When trying to use the class in Java code, Eclipse complains about using the binary name.
Below is an example of Scala code defining the class of interest (Inner
):
package mypackage;
object Outer {
object Middle {
class Inner {
def msg() {
println("Running");
}
}
}
}
To use the class Inner
in Java code, I use the following code:
mypackage.Outer$Middle$Inner inner = new mypackage.Outer$Middle$Inner();
inner.msg();
However, Eclipse (Indigo) compiler complains with the following message at the first line:
The nested type mypackage.Outer$Middle$Inner cannot be referenced using its binary name
Interestingly, the Java code above works when used with NetBeans 6.9.1.
Is this an issue with Eclipse compiler? Are there any flags to allow using binary names? Or, alternatively, is this an issue with Scala or the way I am using it?
Upvotes: 4
Views: 2567
Reputation: 5712
Deeply nested objects cannot be accessed from Java. Neither from Eclipse, command line or any build tool. The bytecode translation loses the nesting information.
Eclipse does not allow you to use $
names, so it will complain. If you care about Java interop, you should stick to Java-like Scala at the boundaries. Top-level classes, pure-traits or abstract classes, no higher-order methods, etc.
Upvotes: 1