Given following code:
val javaLong: java.lang.Long = null
val opt: Option[Long] = Option(javaLong)
I expected opt to be None
but for some reason it is Some(0)
. I also found this bug and it appears that implicit conversion happens before option's apply method.
I think this is still a bug because one wouldn't expect that behavior and I am wondering is there any workaround or some better ways to wrap nulls.
Update: The code above is only a simplified piece. The real example is something like:
Person(Option(doc.getLong()))
where Person is:
case class Person(id: Option[Long])
and method doc.getLong()
is java method that returns java.lang.Long