@Delegate and method overrides

741 views
Skip to first unread message

fritzr

unread,
Mar 14, 2014, 6:43:42 AM3/14/14
to project...@googlegroups.com
Hi guys,
I was just thinking about a new feature which would help us a lot. It would be nice to have the possibility to use the @Delegate annotation but still be able to override certain methods which are introduced by the delegate bean.

So

class A{
public void foo();
public void bar();
}

class B{
@Delegate
A a;

public void foo(){
//custom override here
}}

What do you think?

muued

unread,
Mar 14, 2014, 11:18:40 AM3/14/14
to project...@googlegroups.com
I guess you would need some annotation on the method foo to avoid unwanted prevention of delegation (e.g. editing A without thinking about B), which doesn't seem to be much easier than just using the exclude option for the delegate annotation

Reinier Zwitserloot

unread,
Mar 14, 2014, 2:41:48 PM3/14/14
to project-lombok

It used to work that way, but it gets rather hairy when generics are involved to know if a certain signature is an implementation of one of the methods you are delegating.

You can make an inner private interface with a subset of the methods and then supply this interface to the @Delegate annotation. The field you put the annotation on does not actually have to implement the type you delegate. This way you have exact control of the methods you delegate.

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages