The following Scala example defines a class inside a package object:
package com.mycompany package object test { class MyTest { def foo(): Int = { 42 } } }
The following three classes are generated:
com/mycompany/test/package.class com/mycompany/test/package$.class com/mycompany/test/package$MyTest.class
The problem occurs when trying to use the MyTest class from Java. I think that since package$MyTest contains $ in the name, Java does not recognize its existence. However, the package$ class is available.
Running javap on package$MyTest.class returns:
Compiled from "Test.scala" public class com.mycompany.test.package$MyTest { public int foo(); public com.mycompany.test.package$MyTest(); }
I tried accessing the class using Eclipse, Intellij and Netbeans, without success. Can I use Scala classes defined in package objects from Java?
source share