To save some typing and clarify my code, is there a standard version of the following method?
public static boolean bothNullOrEqual(Object x, Object y) {
return ( x == null ? y == null : x.equals(y) );
}
To save some typing and clarify my code, is there a standard version of the following method?
public static boolean bothNullOrEqual(Object x, Object y) {
return ( x == null ? y == null : x.equals(y) );
}
I know it can be done in VB - http://www.csidata.com/custserv/onlinehelp/VBSdocs/vbs428.htm, it's the EQV operator.
It can be done in Perl, and C++ would view (X==Y) fine if both are NULL.
Based on this page from the Java tutorial from Sun, http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html, it appears to not be possible.
No. I've seen people suggesting putting a similar method in a utility class, but it isn't in the standard library (the Object class seems like a good place, but who am I to suggest it?).
if by some chance you are have access to the Jakarta Commons library there is ObjectUtils.equals() and lots of other useful functions.
EDIT: misread the question initially
I have this method.
For the sake of saving character calories, its named eq
.