I have been always using
a != null
to check that a
is not a null reference. But now I've met another way used:
a.ne(null)
what way is better and how are they different?
I have been always using
a != null
to check that a
is not a null reference. But now I've met another way used:
a.ne(null)
what way is better and how are they different?
Besides that said @drexin and @Jack,
ne
defined in AnyRef and exists only for referential types.Like @Jack said
x ne null
is equal to!(x eq null)
. The difference betweenx != null
andx ne null
is that!=
checks for value equality andne
checks for reference equality.Example: