以下代码来自Arrays
类:
http://developer.classpath.org/doc/java/util/Arrays-source.html
public static <T,U> T[] copyOfRange(U[] original, int from, int to,
Class<? extends T[]> newType)
{
if (from > to)
throw new IllegalArgumentException("The initial index is after " +
"the final index.");
T[] newArray = (T[]) Array.newInstance(newType.getComponentType(),
to - from);
if (to > original.length)
{
System.arraycopy(original, from, newArray, 0,
original.length - from);
fill(newArray, original.length, newArray.length, null);
}
else
System.arraycopy(original, from, newArray, 0, to - from);
return newArray;
}
我对Class<? extends T[]>
感到困惑,如何扩展T[]
?据我所知,即使有K[]
,也没有像T[]
这样的子类型K extends T
这样的数组。