@SuppressWarnings("unchecked")
private static <T> T[] copyOfRange(T[] original, int start, int end){
final int originalLength = original.length;
if(start > end){
throw new IllegalArgumentException();
}
if(start < 0 || end > originalLength){
throw new ArrayIndexOutOfBoundsException();
}
final int resultLength = end - start;
final int copyLength = Math.min(resultLength, originalLength - start);
final T[] result = (T[])Array.newInstance(original.getClass().getComponentType(), resultLength);
System.arraycopy(original, start, result, 0, copyLength);
return result;
}
泛型函数 拷贝数组
最新推荐文章于 2023-12-16 00:56:32 发布