利用反射编写泛型数组代码

public static Object copyOf(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;
}
上一篇:[考试反思]0929csp-s模拟测试55:沦陷


下一篇:OO实现ALV TABLE 四:SALV的显示样式