• Reflection and array


    java.lang.Reflect.Array类提供了动态创建和访问数组元素的各种静态方法。

    package com.sunchao.reflection;
    
    import java.lang.reflect.Array;
    
    /**
     * The array reflection.
     * @author Administrator
     *
     */
    public class ArrayReflection {
    
        public static void main(String args[]) throws Exception {
            Class<?> clazz = Class.forName("java.lang.String");
            String[] array = (String[]) Array.newInstance(clazz, 10);
            Array.set(array, 5, "hello world");
            String index5= (String) Array.get(array, 5);
            System.out.println(index5);
            System.out.println(array[5]);
            System.out.println(int.class);
            System.out.println(Integer.class);
            System.out.println(Integer.TYPE);
        }
    }

    Integer.TYPE 是int的class类型封装 == int.class

    hello world
    hello world
    int
    class java.lang.Integer
    int
  • 相关阅读:
    msp430入门编程41
    msp430入门编程40
    msp430入门编程37
    msp430入门编程36
    msp430入门编程35
    msp430入门编程34
    msp430入门编程33
    msp430入门编程31
    msp430入门编程32
    msp430入门编程30
  • 原文地址:https://www.cnblogs.com/onlysun/p/4530758.html
Copyright © 2020-2023  润新知