Inherited from Serializable
Inherited by implicit conversion any2stringadd from
NullSafe[A] to any2stringadd[NullSafe[A]]
Inherited by implicit conversion StringFormat from
NullSafe[A] to StringFormat[NullSafe[A]]
Inherited by implicit conversion Ensuring from
NullSafe[A] to Ensuring[NullSafe[A]]
Inherited by implicit conversion ArrowAssoc from
NullSafe[A] to ArrowAssoc[NullSafe[A]]
NullSafe is a keyword to perform
null
check.Author:
杨博 (Yang Bo)
The ? operator usually works with Java libraries that may produce
null
.You can use ? annotation to represent a nullable value.
A normal
.
is not null safe, when selectingleft
,right
orvalue
on anull
value.The above code throws an exception because
root.right.left
isnull
. The exception can be avoided by using ? on a nullable value:root.?.right.?.left.?.right.?.value should be(null)
The entire expression will be
null
if one of ? is performed on anull
value.The boundary of a null safe operator ? is the nearest enclosing expression whose type is annotated as
@ ?
.The ? operator is only available on nullable values. A type is considered as nullable if it is a reference type, no matter it is annotated as
@ ?
or not.A type is considered as not nullable if it is a value type.
Alternatively, a type can be considered as not nullable by explicitly converting it to NotNull.
NoneSafe for similar checks on scala.Options.