Is there any good reason Arrays in Java do not extend Collection?
It seems like it would be useful to be able to test someObject instanceof Collection
before iterating across it with for (Object element : someObject)
. Instead, from what I understand, the only way to know if an object is an array is to either use instanceof
on every array type (Object[]
, int[]
, double[]
, ...) or to use someObject.getClass().isArray()
but then this of course also forces a null check.