通过反射取得并修改数组信息

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] + ",");
        }
    }
}

原文地址:https://www.cnblogs.com/vonk/p/3956546.html