注解与反射(3)
反射
哪些类型可以有class对象
class:外部类,成员(成员内部类,静态内部类),局部内部类,匿名内部类。
interface:接口
[]:数组
enum:枚举
annotation:注解@interface
primitive type:基本数据类型
void
package com.yangxu.Annotation.reflection;
import java.lang.annotation.ElementType;
public class Test03 {
public static void main(String[] args) {
Class c1 = Object.class;
Class c2 = Override.class;
Class c3 = Comparable.class;
Class c4 = String[].class;
Class c5 = int[][].class;
Class c6 = void.class;
Class c7 = Integer.class;
Class c8 = Class.class;
Class c9 = ElementType.class;
System.out.println(c1);
System.out.println(c2);
System.out.println(c3);
System.out.println(c4);
System.out.println(c5);
System.out.println(c6);
System.out.println(c7);
System.out.println(c8);
System.out.println(c9);
int[] a = new int[10];
int[] b = new int[100];
System.out.println(a.getClass().hashCode()==b.getClass().hashCode());
}
}
Java内存分析
类的加载与ClassLoader的理解
三个过程:加载——>链接——>初始化
具体的:
package com.yangxu.Annotation.reflection;
public class ReviewLearned {
public static void main(String[] args) {
MyView myView = new MyView();
System.out.println(MyView.num);
}
}
class MyView{
static {
System.out.println("这是静态代码块");
int num = 10;
}
static int num = 100;
public MyView() {
System.out.println("这是无参构造器");
}
}
画图的理解:
|