Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why use null != anything instead of anything!=null? [duplicate]

Tags:

java

null

equals

I have seen various codes of my seniors and they have used this at many places.What effect does it have? why cant they include anything != null. This is true for below thing too

"true".equals(x).

Why is this so?

like image 454
Nilesh Avatar asked Dec 05 '22 21:12

Nilesh


1 Answers

anything != null is exactly equivalent to null != anything.

On the other hand, "true".equals(x) avoids the need to check if x is null when doing x.equals("true").

like image 183
M A Avatar answered Dec 22 '22 00:12

M A