You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A @DeepClone annotation that, when placed on a class, generates a deepClone() method. This method would create and return a new object instance with all its fields deeply copied. The goal is to reduce boilerplate code where developers currently must manually write clone logic, especially in classes with nested objects.
publicclassPerson {
privateStringname;
privateAddressaddress;
publicPersondeepClone() {
Personclone = newPerson();
clone.name = this.name;
// In case if address doesn't have deepClone method, we can clone the reference.clone.address = (this.address == null) ? null : this.address.deepClone();
returnclone;
}
}
// For completeness, the Address class would need its own deepClone logic:publicclassAddress {
privateStringstreet;
privateStringcity;
publicAddressdeepClone() {
Addressclone = newAddress();
clone.street = this.street;
clone.city = this.city;
returnclone;
}
}
Describe the target audience
This feature would benefit Java developers who work with complex, nested object graphs and frequently need a deep copy of their objects. For instance, developers building domain models with hierarchical structures, DTOs, or configuration objects that must be safely cloned to avoid unintended mutations. Such developers currently must manually implement deep cloning or rely on external utilities, which leads to boilerplate and potential errors.
Additional context
Deep cloning is a common requirement in many applications but is often repetitive and error-prone if done manually. While libraries like Apache Commons Lang provide a reflection-based cloning approach, a Lombok-generated method would be more efficient, type-safe, and integrated with existing Lombok features. Implementing @DeepClone would align with Lombok’s goal of reducing boilerplate while maintaining performance and clarity.
The text was updated successfully, but these errors were encountered:
Hello Volodya, I would like to take up this issue, however I am new to this but I have atleast studied some cloning before, is there any thing I would need to know to get started with this issue other than what you have stated thank you very much.
You should not start working on this before you get an approval from the maintainers. Otherwise you'd risk getting your PR rejected, either because you chose a wrong approach, or the feature or solution in itself is flawed, or too difficult to maintain.
In this case, I'm quite sure the maintainers will consider the whole feature flawed. It was already discussed a few times, and it will simply never meet the expectations Lombok users would have: You would need deep-cloning enabled on all referenced classes, and you can neither ensure that nor even detect that one of the referenced classes does not support it.
Describe the feature
A
@DeepClone
annotation that, when placed on a class, generates adeepClone()
method. This method would create and return a new object instance with all its fields deeply copied. The goal is to reduce boilerplate code where developers currently must manually write clone logic, especially in classes with nested objects.Lomboked Version (Conceptual Example)
What Lombok Would Generate Under the Hood
Describe the target audience
This feature would benefit Java developers who work with complex, nested object graphs and frequently need a deep copy of their objects. For instance, developers building domain models with hierarchical structures, DTOs, or configuration objects that must be safely cloned to avoid unintended mutations. Such developers currently must manually implement deep cloning or rely on external utilities, which leads to boilerplate and potential errors.
Additional context
Deep cloning is a common requirement in many applications but is often repetitive and error-prone if done manually. While libraries like Apache Commons Lang provide a reflection-based cloning approach, a Lombok-generated method would be more efficient, type-safe, and integrated with existing Lombok features. Implementing
@DeepClone
would align with Lombok’s goal of reducing boilerplate while maintaining performance and clarity.The text was updated successfully, but these errors were encountered: