Reputation: 6423
I am having trouble accessing the method fromString in Scala. I tried javap and at least one of the ways i am accessing should be working, but its not.
App.scala
object App {
def fromString(s:String) : Option[Int] = if( s == "0" ) Some(0) else None
}
Test.java
public class Test {
public static void main(String[] args){
//THEY ALL GIVE COMPILER ERRORS
//App.fromString("");
//App$.fromString("") ;
//App$.MODULE$.fromString("");
}
}
JAVAP OUTPUTS
javap App Compiled from "App.scala"
public final class App extends java.lang.Object{
public static final scala.Option fromString(java.lang.String);
}
javap App$ Compiled from "App.scala"
public final class App$ extends java.lang.Object implements scala.ScalaObject{
public static final App$ MODULE$;
public static {};
public scala.Option fromString(java.lang.String);
}
Upvotes: 0
Views: 1014
Reputation: 51109
I just tried it in Eclipse, and the expected
App.fromString("");
compiles fine. Eclipse shows an error "App cannot be resolved", but I've learnt to ignore Eclipse's errors.
Maybe you haven't put your classes in the same package?
Upvotes: 1