What is the difference between the performance of new object and clone object in java
This article mainly introduces what is the difference between the performance of a new object and a clone in java. It has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
An object created by new is:
1. Create a space in memory;
2. Create objects in the opened memory space;
The constructor of the object is called to initialize the object.
The process of creating an object through clone is:
1, according to the original object memory size to open up a memory space;
2. Copy an existing object and clone all attribute values in the object.
Compared to new, clone calls fewer constructors.
Java objects that require a large amount of contiguous memory space are generally called large objects, such as long strings, arrays, and class objects
If there are a large number of attribute initializations or large objects in the constructor, the way to copy objects using clones performs better.
Thank you for reading this article carefully. I hope that Xiaobian will share the article "What is the difference between the performance of a new object and a clone object in java?" This article is helpful to everyone. At the same time, I hope that everyone will support it more. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!