Feature: Encapsulation and collections using the Delegate annotation

30 views
Skip to first unread message

Timothy Spear

unread,
Mar 9, 2026, 8:15:14 AMMar 9
to Project Lombok
In an ideal world, we are supposed to encapsulate collections/sets and other attributes within the object and not expose it.
Doing so requires fairly extensive boilerplate code; which is why I never bother doing it. Based on searching, I think that has come up more than once, but most of the requests I found were rather old. 

However, I have yet to see any suggestions to do tied to the Delegate annotation. 

With two (what I hope are minor) changes the existing delegate annotation could do the job. 
Add two attributes to Delegate:
1. prefix 
2. methodMap

If prefix is enabled, generate the new method name by appending the variable to the method name from the interface, following the same logic as Getter/Setter.
MethodMap would allow for name changes. e.g. I would want to standardize "add" as my public method name, and map it to "put", for example.

Tim

Neale Upstone

unread,
Mar 24, 2026, 4:27:31 AM (14 days ago) Mar 24
to Project Lombok
So if we're doing:

@Delegate(types=List.class)
private ArrayList<Cat> cats;

Wouldn't suffix="Cat" also be useful?

Timothy Spear

unread,
Mar 26, 2026, 8:25:54 AM (11 days ago) Mar 26
to Project Lombok
Neale,

Sure, a suffix using the variable name would also work.

Tim 
Reply all
Reply to author
Forward
0 new messages