1
package com.szsm.swing.other;
import java.lang.reflect.Array;
public class Answer_1606 {
public static void main(String[] args) {
Test test = new Test();
test.is = (int[]) addArrayLength(test.is, 10);
test.ss = (String[]) addArrayLength(test.ss, 10);
test.print();
}
public static Object addArrayLength(Object array, int newLength) {
Object newArray = null;
Class componentType = array.getClass().getComponentType();
newArray = Array.newInstance(componentType, newLength);
System.arraycopy(array, 0, newArray, 0, Array.getLength(array));
return newArray;
}
}
class Test {
public int[] is = { 1, 2, 3 };
public String[] ss = { "A", "B", "C" };
public void print() {
for (int index = 0; index < is.length; index++) {
System.out.println("is[" + index + "]=" + is[index]);
}
System.out.println();
for (int index = 0; index < ss.length; index++) {
System.out.println("ss[" + index + "]=" + ss[index]);
}
System.out.println();
}
}
2
is[0]=1
is[1]=2
is[2]=3
is[3]=0
is[4]=0
is[5]=0
is[6]=0
is[7]=0
is[8]=0
is[9]=0
ss[0]=A
ss[1]=B
ss[2]=C
ss[3]=null
ss[4]=null
ss[5]=null
ss[6]=null
ss[7]=null
ss[8]=null
ss[9]=null
是否调用2
是否调用
is[0]=1
is[1]=2
is[2]=3
is[3]=0
is[4]=0
is[5]=0
is[6]=0
is[7]=0
is[8]=0
is[9]=0
ss[0]=A
ss[1]=B
ss[2]=C
ss[3]=null
ss[4]=null
ss[5]=null
ss[6]=null
ss[7]=null
ss[8]=null
ss[9]=null