Java利用反射技术实现任意类型数组的扩展

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)