消除非受检警告.jpeg
加在方法上
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
if (a.length < size)
// Make a new array of a's runtime type, but my contents:
return (T[]) Arrays.copyOf(elementData, size, a.getClass());
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
加在变量上
public <T> T[] toArray(T[] a) {
if (a.length < size){
// Make a new array of a's runtime type, but my contents:
@SuppressWarning("unchecked")
T[] result = (T[])Arrays.copyOf(elements,size,a.getClass());
return result;
}
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
网友评论