문제

The javadoc of ArrayUtils.isNotEmpty() in Apache Commons Lang seems to be wrong. Or, at least, misleading. It says

Returns: true if the array is not empty or not null

In my understanding, an empty array is not null. So, according to the above definition, isNotEmpty() should return true for an empty array, which is counterintuitive.

Wouldn't

Returns: true if the array is not null and not empty

be more correct?

도움이 되었습니까?

해결책

Wouldn't

Returns: true if the array is not null and not empty

be more correct?

Yes you are right. The doc is a bit misleading. In fact, if you see the source code, it does exactly that:

public static boolean isNotEmpty(Object[] array) {
   return (array != null && array.length != 0);
}

다른 팁

In my understanding, an empty array is not null.

Not correct. Counterexample:

int a[];

a is an empty array (as it doesn't contain anything), and it's also null since it wasn't initialized.

In this case, isNotEmpty will return false, since it is empty.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top