static Object ArrayGrow(Object arr){
Class cl = arr.getClass();
if (!cl.isArray()) {
return null;
}
Class componentTyoe = cl.getComponentType();
int length = Array.getLength(arr);
int newLength = length * 11/10 + 10;
Object newArray = Array.newInstance(componentTyoe, newLength);
System.arraycopy(arr, 0, newArray, 0, length);
return newArray;
}
Java利用反射技术实现任意类型数组的扩展
最新推荐文章于 2021-02-27 06:01:04 发布