您的位置:首页 > 其它

数组的反射

2014-10-27 23:13 85 查看
所有类型相同,维度相同的数组都属于同一段字节码,同一种类型
package com.best.array;

public class TestArray {

/** 所有类型相同,维度相同的数组都属于同一段字节码,同一种类型  **/
public static void main(String[] args) {

int [] a1 = new int[3];
int [] a2 = new int[4];
int[][] a3 = new int[2][3];
int[][] a4 = new int[4][4];
System.out.println(a1.getClass() == a2.getClass());
System.out.println(a3.getClass() == a4.getClass());
/** "["-代表数组,"I"--代表整数,预期输出:[I **/
System.out.println(a1.getClass().getName());
/** "["-代表数组,"I"--代表整数,预期输出:[[I **/
System.out.println(a3.getClass().getName());
}

}


输出:

true
true
[I
[[I


中括号:代表数组,I--代表整数类型,可以参考API文档反射的getName方法描述
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: