Re: [project lombok] @Adder annotation

493 views
Skip to first unread message

Leon Blakey

unread,
Feb 6, 2012, 7:53:46 PM2/6/12
to project...@googlegroups.com
This seems like just a smaller version of delegates. And adding simplifications of simplifications of common code doesn't make much sense to me

2012/1/31 Vojtěch Knyttl <voj...@knyt.tl>
What about adding some kind of @Adder annotation:

@Adder
protected Set<Performer> performers = new HashSet<Performer>();

would generate:

public void addPerformer(Performer object) {
     performers.add(object);
}

Thanks for considering.

--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

sinuhepop

unread,
Feb 13, 2012, 7:15:34 AM2/13/12
to Project Lombok
I don't agree with you, Leon. Imagine this class:

public class A{
@Adder private List<B> b = new ArrayList<B>();
@Adder private List<C> c = new ArrayList<C>();
}

How can you do what @Adder would do using @Delegate?

Anyway, I think that would be useful to accept maps too:

@Adder private Map<A, B> thing = new HashMap<A, B>();

and generates:

public void addThing(A, B) {...}




On Feb 7, 1:53 am, Leon Blakey <lord.quacks...@gmail.com> wrote:
> This seems like just a smaller version of delegates. And adding
> simplifications of simplifications of common code doesn't make much sense
> to me
>
> 2012/1/31 Vojtěch Knyttl <vojt...@knyt.tl>
>
>
>
>
>
>
>
> > What about adding some kind of @Adder annotation:
>
> > @Adder
> > protected Set<Performer> performers = new HashSet<Performer>();
>
> > would generate:
>
> > public void addPerformer(Performer object) {
> >      performers.add(object);
> > }
>
> > Thanks for considering.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups group forhttp://projectlombok.org/

eric.giese

unread,
Feb 27, 2012, 5:40:32 AM2/27/12
to Project Lombok
The adding pattern itself is not useful:
1) Constrained to specific datatypes (anything that implements
colleciton or similar interfaces)
2) You cannot apply generic collection algorithms if you do not have
access to the iterable itself.
3) Using a getter (returning an Unmodifiable collection!) and a setter
provides a much higher reusability of the code without any downsides.

2 and 3 are my personal opinion, but 1 might be the showstopper:
Lombok is about providing generic annotations for very common
problems, and not about pin-point-solutions.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages