import java.lang.reflect.Array;
public class ClassArrayDemo {
public static void main(String[] args) {
int temp[] = { 1, 2, 3 };
Class<?> c = temp.getClass().getComponentType();
System.out.println("TYPE:" + c.getName());
System.out.println("LENGTH:" + Array.getLength(temp));
System.out.println("FRIST CONTENT:" + Array.get(temp, 0));
Array.set(temp, 0, 6);
System.out.println("LENGTH:" + Array.getLength(temp));
System.out.println("FRIST CONTENT:" + Array.get(temp, 0));
for (int i = 0; i < temp.length; i++) {
System.out.print(temp[i] + ",");
}
}
}
时间: 2024-10-10 00:00:06