How can you access scala.None from Java?
The last line causes the compiler to die with "type scala.None does not take parameters".
import scala.Option;
import scala.Some;
import scala.None;
final Option object1 = new Some("Hi there");
final Option object2 = new None();
This fails with "cannot find symbol constructor None()":
final Option object2 = new None();
This fails with "cannot find symbol variable None":
final Option object2 = None;
In 2007 this used to work, but then Scala changed. The Java compiler gives error: incompatible types:
final Option object2 = scala.None$.MODULE$;
解决方案
This might work:
final scala.Option x = scala.Option.apply(null);
def apply [A] (x: A): Option[A]
An Option factory which creates
Some(x) if the argument is not null, and None if it is null.