You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser.
yodacondition
About this tag
The yodacondition tag on WindowsForum.com covers discussions about the Yoda condition programming idiom, where a constant is placed on the left side of an equality comparison to avoid null pointer exceptions. In Java, this technique is used when calling .equals() on a potentially null string by writing "constant".equals(variable) instead of variable.equals("constant"). While this prevents NullPointerException, some developers find it less readable and prefer explicit null checks. The tag includes threads debating the merits of Yoda conditions versus direct null handling, focusing on Java coding practices and readability.
In Java, if I try to do.equals() on a null string, a null pointer error is issued. I’m wondering whether I can perform the following if I’m attempting to compare if a string is equal to a constant string:
MY CONSTANT STRING.equals(aStringVariable)
I’m sure it’ll work, but is this simply...