May 10, 2021 Java
An instance object of a Class class that records class description information.
Class classes do not have a common construction method and cannot be instantiated by new operators; t
o get an instance.
Method | Objective |
---|---|
static ClassforName(String className)throws ClassNotFoundException | Use the parameter className to specify a specific class to get the relevant class description object, which is likely to throw a ClassNotFoundException that must be snapped |
Class getSuperclass() | Gets the description object of the parent class of the current class description object |
String getName() | Returns the class name of the object described by the current class |
There are three ways to get Class objects:
public class _T11 {
// Class:类描述对象
public static void main(String[] args) {
Class<?> _class;
// ***1*对象.getClass()
String str = "";
_class = str.getClass();
System.out.println(_class + "-----对象名.getClass()");
// ***2*类.class
_class = String.class;
System.out.println(_class + "-----类名.class");
// ***3*Class.forName("")
try {
_class = Class.forName("java.lang.String");
System.out.println(_class + "-----Class.forName(...)");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
class java.lang.string----- object name.getClass()
Class java.lang.String ----- class name .class
class java.lang.String-----Class.forName(...)