随笔分类 -  注解及反射

摘要:2.0、通过反射动态创建对象执行的方法 public class Test09 { public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationE 阅读全文
posted @ 2020-06-30 09:33 小徐学狂 阅读(415) 评论(0) 推荐(0)
摘要:1.9、获取类的运行时结构 public class Test08 { public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException 阅读全文
posted @ 2020-06-29 17:35 小徐学狂 阅读(139) 评论(0) 推荐(0)
摘要:1.8、分析类的初始化 public class Test06 { static { System.out.println("Main类被加载"); } public static void main(String[] args) throws ClassNotFoundException { // 阅读全文
posted @ 2020-06-28 10:23 小徐学狂 阅读(122) 评论(0) 推荐(0)
摘要:1.7、类加载内存分析 public class Test05 { public static void main(String[] args) { A a = new A(); System.out.println(a.m); } } class A{ static { System.out.pr 阅读全文
posted @ 2020-06-28 10:01 小徐学狂 阅读(155) 评论(0) 推荐(0)
摘要:1.6、所有类型的Class public class Test04 { public static void main(String[] args) { Class c1 = Object.class; //类 Class c2 = Comparable.class; //接口 Class c3 阅读全文
posted @ 2020-06-27 21:09 小徐学狂 阅读(257) 评论(0) 推荐(0)
摘要:1.5、Class类的创建有哪些? public class Test03 { public static void main(String[] args) throws ClassNotFoundException { Person person = new Student(); System.o 阅读全文
posted @ 2020-06-27 20:49 小徐学狂 阅读(196) 评论(0) 推荐(0)
摘要:1.4、反射 public class Test02 { public static void main(String[] args) throws ClassNotFoundException { //通过反射获取类的class对象 Class<?> c1 = Class.forName("com 阅读全文
posted @ 2020-06-27 20:48 小徐学狂 阅读(119) 评论(0) 推荐(0)
摘要:1.3、自定义注解 public class Test03 { //对于没有默认值的注解必须显示赋值 // 有默认值的注解可以不再赋值 @MyAnnotation2(id = 11) public void test(){}; //注解只有一个参数时 多用value // 可以在配置的地方省略 va 阅读全文
posted @ 2020-06-27 10:41 小徐学狂 阅读(118) 评论(0) 推荐(0)
摘要:注解和反射 1.1、 几个内置常用注解 //抑制警告,可以修饰在类和方法上 @SuppressWarnings("all") public class Test01 { //@Override 重写的注解 @Override public String toString() { return sup 阅读全文
posted @ 2020-06-27 09:38 小徐学狂 阅读(165) 评论(0) 推荐(0)