【发布时间】:2020-03-12 19:59:43
【问题描述】:
以下代码来自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;
}
我对@987654324@ 部分感到困惑,如何扩展T[]?据我所知,没有像K[] 这样的数组是T[] 的子类型,尽管K extends T。
【问题讨论】: