本帖最后由 佟都 于 2013-8-6 00:11 编辑
可以用反射自己写段代码验证下
- import java.lang.reflect.*;
- import java.util.Arrays;
- public class ReflectTest {
- public static void main(String[] args) throws Exception {
- String str1 = "abc";
- //数组的反射操作
- //int [] a1 = new int[3];
- int [] a1 = new int[]{1, 2, 3};
- int [] a2 = new int[4];
- int[][] a3 = new int[2][3];
- //String [] a4 = new String[3];
- String [] a4 = new String[]{"a", "b", "c"};
-
- Class a1Clz = a1.getClass();
- Class a2Clz = a2.getClass();
- Class a3Clz = a3.getClass();
- Class a4Clz = a4.getClass();
- System.out.println("a1Clz == a2Clz is "+ (a1Clz == a2Clz));
- System.out.println("a1Clz == a3Clz is "+ (a1Clz == a3Clz));
- System.out.println("a1Clz == a4Clz is "+ (a1Clz == a4Clz));
- //JDK1.6 : Incompatible operand types Class
- //System.out.println(a1.getClass() == a4.getClass());
- //获取Array的Class类型名
- System.out.println("a1.getClass().getName() = "+ a1Clz.getName());
- //获取Array的父类Class类型名
- System.out.println("a1Clz.getSuperclass().getName() = "+ a1Clz.getSuperclass().getName());
- System.out.println("a4Clz.getSuperclass().getName() = "+ a4Clz.getSuperclass().getName());
- }
- }
复制代码 |