I'm feeling quite silly for asking this question, but I've already seen this code on two separate corporate codebases and I'm starting to think there's some chunk of ancient java knowledge I'm not aware of.
So, we got this kind of code:
/* Lot of corporate stuff */
if (ClassicUtilsClass.isNotNull(variable)) {
/* Variable handling shenanigans. */
}
Going to our ClassicUtilsClass revealed the implementation of the function:
/* Lot of useful static functions*/
public static isNotNull(Object o) {
return o!=null;
}
public static isNull(Object o) {
return o==null;
}
I read it, scratched my head, looked around the internet, asked colleagues and friends, then laugh at the uselessness of the function. Then I switched jobs and a colleague showed me more or less the same code.
In the same codebase we have the classic "isNullOrEmpty" which does the standard "return object==null || object.size() == 0;", so I can understand having a function to wrap the null comparison... plus something else, but I don't see the point of creating a whole new function for null checking.
I'm losing something here?