What is the difference between a.ne(null) and a != null in Scala?
null, scala
Solution
Like @Jack said `x ne null` is equal to `!(x eq null)`. The difference between `x != null` and `x ne null` is that `!=` checks for value equality and `ne` checks for reference equality.
Example:
scala> case class Foo(x: Int)
defined class Foo
scala> Foo(2) != Foo(2)
res0: Boolean = false
scala> Foo(2) ne Foo(2)
res1: Boolean = true
Problem
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?