重写Arrays.copyOf方法
origin
Employee a[]=new Employee[100];
System.out.println(a.length);
a = Arrays.copyOf(a, a.length * 2);
System.out.println(a.length);
badCopyOf
Object a[]=new Employee[100];
System.out.println(a.length);
a = Main.badCopyOf(a, a.length * 2);
System.out.println(a.length);
goodCopyOf
public static Object goodCopyOf(Object[] a,int newLength){
Class cl = a.getClass();
if(!cl.isArray()) return null;
Class componentType = cl.getComponentType();
int length = Array.getLength(a);
Object newArray = Array.newInstance(componentType, newLength);
System.arraycopy(a,0,newArray,0,Math.min(length,newLength));
return newArray;
}