3 ways to get the Class object of a class

There are three ways to load and get the Class object of a class:

    Class.forName, instance object.class(attribute), instance object getClass()

Their differences:

    1) Class cl=A.class: JVM will use the class loader of class A to load class A into memory (provided that class A has not been loaded into memory), and does not do class initialization for class A. Return class A The Class object.

   2) Class cl=object reference o.getClass(): Returns the object of the class to which the reference o actually refers to at runtime (because: the reference of the child object may be assigned to the reference variable of the parent object) of the class to which it belongs.

   3) Class.forName("class name"): Load class A and initialize the class.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326821142&siteId=291194637