java bytecode

Overview of bytecode objects (bytecode is an address identifier used by jvm to locate the position of a class, and is used to find the position of a class in the JVM)

After each class is loaded, the system will generate a corresponding bytecode object for the class, through which the corresponding class in the JVM can be accessed. There are usually three ways to obtain a Class object in Java.

Three ways to obtain bytecode objects

1. Use the .class attribute of the class

Class<类类型> clz1 = 类名.class;

2. Through the static method forName (String className) in the Class class, the fully qualified name of the incoming class (the complete package name must be added) is more commonly used

Class<?> clz2 = Class.forName("java.util.Date");

3. Realized by the getClass method of the object, where getClass() is a method in the Object class, and all objects can call this method

Date str = new Date();
Class<?> clz3 = str.getClass();

Frequently used range: Pass in as a parameter
when obtaining reflection and when
defining the position of your own class in the JDBC template

Guess you like

Origin blog.csdn.net/qq_45788043/article/details/111599942