Accessing scala.None from Java

前端 未结 6 1996
南笙
南笙 2020-12-04 01:14

How can you access scala.None from Java?

The last line causes the compiler to die with \"type scala.None does not take parameters\".

imp         


        
6条回答
  •  半阙折子戏
    2020-12-04 01:58

    You can do the following (I tested it out and it works fine for me with Scala 2.9.1 and Java 1.6):

     final Option obj1 = Some.apply(null) // This will give you a None;
     System.out.println(obj1.getClass()); // will print "class scala.None$
    
     final Option obj2 = Some.apply("Something");
     System.out.println(obj2.getClass()); //will print "class scala.Some
    

提交回复
热议问题