None
instead of Some(null)
SC-A1002It is more idiomatic in scala to use Option
, i.e. Some
and None
instead of null
. Using Some(null)
instead of None
defeats the entire purpose of Option
. However, there might be certain scenarios where this is a legitimate approach, such as when dealing with Java-based libraries, to improve compatibility.
Carefully consider whether using Option
with null
is necessary before doing so.
container.get(key) match {
case Some(null) => // no such key
// ...
}
container.get(key) match {
case None => // no such key
// ...
}