I do not think so. As far as I know, there is no magic for zeros. (see Update)
I think the best thing you can do is wrap any object in a parameter so that you can use a bunch of useful things from it:
implicit def toOption[T](target: T) = Option(target) val q: String = null val q1: String = "string" println(q getOrElse "null") // prints: null println(q1 getOrElse "null") // prints: string
Update
I found this document:
http://www.scala-lang.org/api/2.7.7/scala/Null.html
In accordance with this:
The Null class - along with the Nothing class - is at the bottom of the Scala type hierarchy.
That way, even null has methods inherited from AnyRef , such as eq , == , etc .... And you can also use them:
val q: String = null val q1: String = "string" println(null eq q) // prints: true println(null eq q1) // prints: false
source share