1. Call the getClass() method in the Object class:
import java.util.Date; public class ReflectTest3 { public static void main(String[] args) { Date date = new Date(); Class<?> cls = date.getClass(); System.out.println(cls); } } "class java.util.Date"
2. Use "class.class" to obtain:
import java.util.Date; public class ReflectTest4 { public static void main(String[] args) { Class<?> cls = Date.class; System.out.println(cls); } } "class java.util.Date"
3. Call a method provided by the Class class - instantiate the Class object
public class ReflectTest5 { public static void main(String[] args) throws ClassNotFoundException { Class<?> cls = Class.forName("java.util.Date"); System.out.println(cls); } } "class java.util.Date"
The above is the detailed content of What are the three instantiations of Class in java. For more information, please follow other related articles on the PHP Chinese website!