注解与反射(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内存分析
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8ohf7o5P-1647253099023)(C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20220314172944831.png)]](https://img-blog.csdnimg.cn/93d17c0b4ced4b4986a023149ca058bb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5aW95aW95a2m5Lmg5LqJ5Y-W5L-d56CU,size_17,color_FFFFFF,t_70,g_se,x_16)
类的加载与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("这是无参构造器");
}
}
画图的理解:
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QrfVD7vq-1647253099024)(C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20220314181419644.png)]](https://img-blog.csdnimg.cn/19bdb16dbd7444e29edd1ada96e6d7db.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5aW95aW95a2m5Lmg5LqJ5Y-W5L-d56CU,size_20,color_FFFFFF,t_70,g_se,x_16)
|