in a tutorial (for implementing a xml parser) i saw the following code:
if( "NODENAME".equals(xmlreader.getNodeName()) ) { // getNodeName() returns java.lang.String
...
}
Is there a reason to write a string comparision like that?.
This may be some kind of best/bad practice or code like that could give some performance benefit. I would like to know if i should use this in commercial projects.
That saves you from a NullPointerException.
That is Yoda Condition used to solve unsafe null behavior.
In programming jargon, Yoda Conditions (also called Yoda Notation) is a programming style where the two parts of an expression are reversed in a conditional statement.
Advantage is
Swapping the two conditional values does not change the behavior of the program. A common mistake is to accidentally assign a value instead of writing a conditional statement.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다