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:
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: