Accessing scala.None from Java

前端 未结 6 1991
南笙
南笙 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:56

    Using Scala version 2.11.4 the only thing that worked out in my case, was

    Option maybeAmount = (amount != MISSING_STOCKAMOUNT) 
    ? Some.apply(amount+"") : Option.apply(null); // can you feel the pain??
    

    Update: a day later...

    Option.apply(null);
    

    without the type parameter does work too, as it should. For some reason I couldn't get Intellij to compile the code on my first attempt. I had to pass the secondary type parameter. Now it compiles, just don't ask

提交回复
热议问题