0

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);
}
1
  • Have you tried App.MODULE$.fromString(""); so far? Commented May 22, 2012 at 20:10

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Huh, how silly. I have not yet learnt to ignore errors in Eclipse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.