Package lombok.experimental
Annotation Type Delegate
Put on any field to make lombok generate delegate methods that forward the call to this field.
Example:
private @Delegate List<String> foo;will generate for example an
boolean add(String)
method, which contains: return foo.add(arg);
, as well as all other methods in List
.
All public instance methods of the field's type, as well as all public instance methods of all the field's type's superfields are delegated, except for all methods
that exist in Object
, the canEqual(Object)
method, and any methods that appear in types
that are listed in the excludes
property.
Complete documentation is found at the project lombok features page for @Delegate.
-
Optional Element Summary
Optional Elements
-
Element Details
-
types
Class<?>[] typesNormally the type of the field is used as delegate type. However, to choose a different type to delegate, you can list one (or more) types here. Note that types with type arguments can only be done as a field type. A solution for this is to create a private inner interface/class with the appropriate types extended, and possibly with all methods you'd like to delegate listed, and then supply that class here. The field does not actually have to implement the type you're delegating; the type listed here is used only to determine which delegate methods to generate. NB: All methods inObject
, as well ascanEqual(Object other)
will never be delegated.- Returns:
- For each method (not already in
java.lang.Object
) in these types, generate a delegate method.
- Default:
{}
-
excludes
Class<?>[] excludesEach method in any of the types listed here (include supertypes) will not be delegated. NB: All methods inObject
, as well ascanEqual(Object other)
will never be delegated.- Returns:
- For each method (not already in
java.lang.Object
) in these types, skip generating a delegate method (overridestypes()
).
- Default:
{}
-