Accessing scala.None from Java

前端 未结 6 1997
南笙
南笙 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条回答
  •  旧时难觅i
    2020-12-04 01:52

    Not to put too fine a point on it, but one shouldn't rely on static forwarders, as they might not get generated under certain circumstances. For instance, Some doesn't have static forwarders for its object companion.

    The current way of accessing methods on an object companion is this:

    final scala.Option x = scala.Option$.MODULE$.apply(null);
    

    Option$ is the class for the object companion of Option. MODULE$ is a final public static field that contains the sole instance of Option$ (in other words, the object companion).

提交回复
热议问题