Reputation: 67
I was reading at the Oracle java API document about System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
method. ArrayStoreException
is thrown when the src/dest argument refers to an object that is not an array. Then is it possible to to use Arrays or T[] in the method declaration? Something like:
System.arraycopy(Arrays src, int srcPos, Arrays dest, int destPos, int length)
or
System.arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length)
Upvotes: 1
Views: 76
Reputation: 122429
System.arraycopy()
can be used on both arrays of primitives, and arrays of references. T[]
can only be used with arrays of references -- T
represents a reference type. The only supertype of both array-of-primitives types and array-of-references types is Object
(well, there are some interfaces like Cloneable
and Serializable
that are also supertypes for all array types but they are not appropriate).
Upvotes: 1