I have the following scala example:
class Nested {}
object Nested {
class Inner {}
object Inner {
def x = 321
}
}
With a JUnit test to test specifically that I can do Nested.Inner.x() and call the method freely without the Nested.Inner$.MODULE$.x():
import static junit.framework.Assert.*;
import org.junit.Test;
public class TestFromJava {
@Test
public void accessTest() {
assertEquals(321, Nested.Inner.x());
}
}
This compiles, but at the moment of running the test, I am getting (sbt test):
[error] TestFromJava.java:8: cannot find symbol
[error] symbol: method x()
[error] location: class Nested.Inner
[error] Nested.Inner.x
How can I benefit from both Scala syntax and not using the horrible $? Maybe it is a feature of the language as how it generates the object instances.
sbt test:compile? I think you pretty much do need to access that symbol throughNested.Inner$.MODULE$.x()sbt clean compilesucceeds.TestFromJava, is that main sources or test sources? Is that insrc/main/javaorsrc/test/java(assuming you have an sbt build - can you confirm this?).compiledoes not compile test-sources, it's short forcompile:compile. You need to runtest:compile.$MODULEfor 2.11.sbt test:compileit complains about the same compilation error from above. @yw3410 2.11.7 scala version