• Post Reply Bookmark Topic Watch Topic
  • New Topic

java performance ( comparision operator)  RSS feed

 
Amit Shah shah
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is diff bet (null==var) and (var==null), Which is preferable & why
 
Raymond Villeno
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Shah shah:
What is diff bet (null==var) and (var==null), Which is preferable & why



i think you cannot do (null == var)....
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

The two are indentical in function. The syntax (null == var) usually comes from C/C++ coders where (var = null) with one equal sign instead of two was a common typo not caught by the compiler, but (null = var) is caught. It's a habit you still see fairly often in Java, but the strongly typed syntax of Java allows the compiler to catch the missing equal sign almost all the time so it's nowhere near as important or useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!