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){
}
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){
}
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.
I think the most common method used is the latter, but both achieve the same thing.