In Groovy language, it is very simple to check for null
or false
like:
groovy code:
def some = getSomething()
if(some) {
//
Well, Boolean
cannot be null
, unless passed as a type parameter. The way to handle null
is to convert it into an Option
, and then use all the Option
stuff. For example:
Option(some) foreach { s => println(s) }
Option(some) getOrElse defaultValue
Since Scala is statically type, a thing can't be "a null or is empty string or is zero number etc". You might pass an Any
which can be any of those things, but then you'd have to match on each type to be able to do anything useful with it anyway. If you find yourself in this situation, you most likely are not doing idiomatic Scala.