首页 > 其他 > 详细

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

时间:2014-09-04 18:39:19      阅读:121      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/vonk/p/3956546.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!