Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between (null != x) and (x != null) [duplicate]

I was watching a java programming video tutorial, and it was mentioning that:

if(null != x){
}

is it a good practice to use it like above ?

Does it differ from :

if(x != null){
}
like image 200
Adham Avatar asked Nov 06 '14 23:11

Adham


1 Answers

You're going to want to use the second one.

Both do the same exact thing...compare A to B, or compare B to A - both mean the same thing.

It just makes more sense to use x != null because that is more like how we would say this.

You could ask me "Is x not null?" That seems more natural than "Is null not x?" It makes more sense to us.

like image 126
Alex K Avatar answered Nov 15 '22 01:11

Alex K