What are the benefits of “String”.equals(otherString)

前端 未结 7 1309
故里飘歌
故里飘歌 2021-01-19 04:57

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

if( \"NODENAME\".equals(xmlreader.getNodeName()) ) {  // getNodeName() returns java.l         


        
7条回答
  •  迷失自我
    2021-01-19 05:26

    Its called a Yoda condition and used to avoid NullPointerException. Regarding its use in commercial projects, this is really a design decision - some developers want to be protected against null values whereas others want the fail fast mechanism offered by the conventional notation.

提交回复
热议问题