Module org.eclipse.xtend.lib
Annotation Interface Delegate
Implements interfaces by forwarding method calls to an annotated field or method.
interface I {
def String m()
}
class Foo implements I {
override String m() {
"Foo"
}
}
class Bar implements I {
//This will generate a method m(), which calls foo.m()
@Delegate val foo = new Foo
}
For each interface that the declaring class and the delegate have in common,
an implementation for each method is added if it does not yet exist. This
implementation forwards all calls directly to the delegate. You can restrict
which interfaces to implement using the Class[] value of this
annotation. This is especially useful when there are several delegates that
have some interfaces in common.
Delegate methods can either take
- no arguments
- the name of the method to be called (String)
- the name of the method to be called (String), its parameter types (Class[]) and the actual arguments (Object[]) of the call
- Since:
- 2.7
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
Class<?>[] valueOptional list of interfaces that this delegate is restricted to. Defaults to the common interfaces of the context type and the annotated element.- Default:
{}
-