Builder method to remove an element from a collection or map?

254 views
Skip to first unread message

rene

unread,
Feb 27, 2017, 4:57:21 PM2/27/17
to Project Lombok
Hi all,

I noticed the @Singular annotation to add single elements to a Builder's collection or map. Is there also an annotation to indicate I want to be able to remove an element? I couldn't find it but am quite new to Lombok so may have overlooked.

A very common use case for builders is to return a modified immutable value with one fewer element in a collection/map. Would be nice for Lombok to provide this functionality. The Builder method could look something like this for collections:

FooBuilder foo.toBuilder().removeBar(Bar bar);

Cheers,
Rene

Reinier Zwitserloot

unread,
Feb 27, 2017, 5:04:44 PM2/27/17
to Project Lombok
Lombok does not currently offer a way to do this. It sounds far too exotic to do so; we'd have to either have a removeBar method for all builders, which sounds a bit over-engineered and confusing for normal (not 'toBuilder' based) scenarios, and in addition would eliminate the ability to use guava, which would be a bad idea in general, and break backwards compatibility, or, we'd have to generate this method only if you use the toBuilder form.

Not a feasible idea, I'm afraid.
Reply all
Reply to author
Forward
0 new messages