java - What are the benefits of "String".equals(otherString) -


in tutorial (for implementing xml parser) saw following code:

if( "nodename".equals(xmlreader.getnodename()) ) {  // getnodename() returns java.lang.string ...  } 

is there reason write string comparision that?.

this may kind of best/bad practice or code give performance benefit. know if should use in commercial projects.

that saves nullpointerexception.

that yoda condition used solve unsafe null behavior.

in programming jargon, yoda conditions (also called yoda notation) programming style 2 parts of expression reversed in conditional statement.

advantage

swapping 2 conditional values not change behavior of program. common mistake accidentally assign value instead of writing conditional statement.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -