in a tutorial (for implementing a xml parser) i saw the following code:
if( \"NODENAME\".equals(xmlreader.getNodeName()) ) { // getNodeName() returns java.l
Usually string comparison was written like that to avoid NullPointerException
if xmlreader.getNodeName()
is null, because then you would have
if("NODENAME".equals(null)) {
// ...
}
compared to
if(null.equals("NODENAME")) {
// ...
}
which would've thrown.
This is called Yoda condition:
if you expect xmlreader.getNodeName()
to be null
then it's ok, otherwise I would not rely on this to avoid the exception to be thrown, you should rather deal with it earlier on in your code.