Scala Option(null) expected as None but I got Some(0)

前端 未结 3 653
囚心锁ツ
囚心锁ツ 2021-01-17 14:29
val i: java.lang.Integer = null
val o: Option[Int] = Option(i) // This yields Some(0)

What is the safe wa

3条回答
  •  攒了一身酷
    2021-01-17 15:14

    Faced the same issue before. This questionable behavior is known by the Scala team. Seems that changing it breaks something elsewhere. See https://github.com/scala/bug/issues/11236 and https://github.com/scala/scala/pull/5176 .

提交回复
热议问题