Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
-
Operating System: other
Platform: Other
-
26594
Description
Hi,
I need a method to determine the length of an array which doesn't throw a NPE if
the array is null (this makes the java.lang.reflect.Array.getLength() method
unsuitable for me because it throws a NPE if array is null).
Here is a possible implementation for an Object array:
public static int getLength(final Object[] array) {
if (array == null)
}
or, maybe you can use Object which makes this method usable for primitive arrays
as well:
public static int getLength(final Object array) {
if (array == null) { return 0; }
else
{ return java.lang.reflect.Array.getLength(array); }}
Can someone please add such a method ?
thanks,
Maarten