3 ms·
Using null instead of None means you are more at risk of hitting a NPE. Here are a couple examples: myVar match { case Some(val) => doSomething(val) cas
by ffk 13y ago
Using null instead of None means you are more at risk of hitting a NPE.
Here are a couple examples:
myVar match {
case Some(val) => doSomething(val)
case None => handleNone()
}
myVar.getOrElse("else")
In both of these cases, we eliminated the possibility of a NPE through the use of a language feature. :)
(edited for formatting)
- gclaramunt 13y agoor myVar.map({ val => doSomething(val) }).getOrElse(handleNone())
- EdwardDiego 13y ago> Using null instead of None means you are more at risk of hitting a NPE. I think he's aware of that - he said he's using Scala as a better Java, what would Java be without the odd NPE?