There is absolutely no difference in either semantics or performance.
The ==
in this case is a reference inequality operation; it can never throw NullPointerException
.
JLS 15.21.3 Reference Equality Operators == and !=
If the operands of an equality operator are both of either reference type or the null type, then the operation is object equality.
The result of !=
is false
if the operand values are both null
or both refer to the same object or array; otherwise, the result is true
.
Use whatever is most readable. Usually it's something != null
.
Related questions
- ‘ … != null’ or ‘null != …’ best performance?