I've got this method at the moment that I am trying to refactor.
public static boolean isEmpty(Object value) {
boolean empty = false;
if (value instanceof String && ((String) value).isEmpty()) {
empty = true;
} else if (value instanceof List && ((List<?>) value).isEmpty()) {
empty = true;
} else if (value instanceof String[] && ArrayUtils.isEmpty((String[]) value)) {
empty = true;
} else if (value == null) {
empty = true;
}
return empty;
}
Is there an obviously better way to do this that I am missing?
I know I could put all the conditions on one if
statement using chained ||
statements, but I don't really see how that is better than what I've got now.