I have a Scala application with one Java source file. In the Java file, I have something like this:
package trajspec;
import scalar.;
import ATMunits.;
public class AirspeedCalcs {
public final static double scalarUnitTestDummy = sec;
...
}
And when I try to compile it, I get this:
[error] /home/rpaielli/trajspec/src/main/java/AirspeedCalcs.java:8: cannot find symbol
[error] symbol: variable sec
[error] location: class trajspec.AirspeedCalcs
[error] public final double scalarUnitTestDummy = sec;
I do not understand the problem since I have been doing the same thing in Scala syntax for years with no problem. What am I missing? Why would the symbol be recognized in the Scala source files but not the Java file? Any ideas? Thanks.
It just occurred to me that my second post may have led readers to believe that I found the source of my problem. No, I didn’t. The wildcard asterisks were in my code, but they got lost when I copied it to the post.
Thanks for the suggestion, but adding “static” didn’t work. ATMunits is a package object, so perhaps I do need a static import, but apparently there is another problem as well.
val sec compiles down to a private field and a method-accessor, through which it can be accessed: sec().
Another issue that compiler reports is MODULE$ being a static field, not a class. As such, it can’t be used to import members from object that it references
To summarize,
import static ATMunits.package$.MODULE$;
...
public final static double scalarUnitTestDummy = MODULE$.sec();
You’ll never be able to wildcard-import /members/ of object instances
(import someValue.*;) in Java. There, you can only wildcard-import
types from packages. (import java.util.*;)
Of course, it’s been years since I wrote much Java, so I could easily be
wrong.