- 准备一个简单的注解
package com.yusian.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotatio[......]
注解、反射、文件IO流的综合应用
Leave a reply
package com.yusian.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotatio[......]
Class.forName(String name)
、类名.class
、实例对象.getClass()
private static void getClassDemo() throws Exception{
Class cls1 = Class.forName("java.lang.Object");
System.out.println(cls1); // class java.lang.Object
Class cls2 = Object.class;
System.out.println(cls2); // class java.lang.Object
Object obj = new Object();
Class cls3 = obj.getClass();
System.out.println(cls3); // class java.lang.Object
System.out.println(cls1 == cls2); // true
System.out.println(cls1 == cls3); // true
}
[……]