OBJNESIS framework realizes the technical principles created by constructor -free function objects in the Java library

Objenesis is a framework that can be created in the Java class library to achieve no constructor object objects.In Java, when using the NEW keywords to create objects, the constructor of this class must be called.However, in some cases, we hope to bypass the constructor to create the object directly.This may be because the constructor of some classes is invisible or privatized, or we just want to bypass the constructor to create an object directly.This is the place of martial arts of the ObjenesIS frame. Objeneis is created by using the Java bytecode operation technology.It will analyze the byte code of the target class, position and analyze the relevant information of the constructor, and then create an object instance directly in the JVM memory without calling its constructor.This method bypasses the call of the constructor, so we can create objects without the need to trigger the constructor. Below is an example of creating objects using ObjinSis framework: First of all, we need to add Objenesis to the project.You can use the following maven configuration: <dependency> <groupId>org.objenesis</groupId> <artifactId>objenesis</artifactId> <version>3.2</version> </dependency> Then, we can use the following code to use ObjinSis to create objects: import org.objenesis.Objenesis; import org.objenesis.ObjenesisStd; public class ObjenesisExample { public static void main(String[] args) { Objenesis objenesis = new ObjenesisStd(); MyClass myObject = objenesis.newInstance(MyClass.class); System.out.println(myObject.getClass().getName()); } } class MyClass { private String name; public MyClass() { this.name = "Default Name"; } public MyClass(String name) { this.name = name; } public String getName() { return name; } } In this example, we created an object of a MyClass class, which contains a parameter constructor and a non -parameter constructor.However, when we use the ObjNESIS framework to create an object, we can create an instance without calling the constructor.Therefore, the above code will print "com.example.myclass". Through the Objenesis framework, we can achieve the creation of no constructor object objects in the Java library.This is very useful for object creation in some cases and provides flexible solutions.