Friday, September 08, 2006

Code like this shouldn't compile

I have just found this code in a code review I am conducting, methods should not be written like this. I have posted it here for your reference. If you find yourself writing code like this, turn your PC off and go home. Compilers should have an extra check to ensure tokens do not consist of check, test, etc and a class name.


/**
* @param obj1
* Object
* @param obj2
* Object
* @return boolean
*/
public static boolean checkObject(Object obj1, Object obj2) {
boolean matches = true;

if (obj1 == null) {
matches = (obj2 == null);
} else {
matches = obj1.equals(obj2);
}
return matches;
}

No comments: