<#import "../_features.html" as f> <@f.scaffold title="@Delegate" logline="Don't lose your composition."> <@f.history>

@Delegate was introduced as feature in lombok v0.10 (the experimental package did not exist yet).
It was moved to the experimental package in lombok v1.14; the old version from the main lombok package is now deprecated.

<@f.experimental> Current status: negative - Currently we feel this feature will not move out of experimental status anytime soon, and support for this feature may be dropped if future versions of javac or ecj make it difficult to continue to maintain the feature. <@f.overview>

Any field or no-argument method can be annotated with @Delegate to let lombok generate delegate methods that forward the call to this field (or the result of invoking this method).

Lombok delegates all public methods of the field's type (or method's return type), as well as those of its supertypes except for all methods declared in java.lang.Object.

You can pass any number of classes into the @Delegate annotation's types parameter. If you do that, then lombok will delegate all public methods in those types (and their supertypes, except java.lang.Object) instead of looking at the field/method's type.

All public non-Object methods that are part of the calculated type(s) are copied, whether or not you also wrote implementations for those methods. That would thus result in duplicate method errors. You can avoid these by using the @Delegate(excludes=SomeType.class) parameter to exclude all public methods in the excluded type(s), and their supertypes.

To have very precise control over what is delegated and what isn't, write private inner interfaces with method signatures, then specify these private inner interfaces as types in @Delegate(types=PrivateInnerInterfaceWithIncludesList.class, excludes=SameForExcludes.class).

<@f.snippets name="experimental/Delegate" /> <@f.confKeys>
lombok.delegate.flagUsage = [warning | error] (default: not set)
Lombok will flag any usage of @Delegate as a warning or error if configured.
<@f.smallPrint>

When passing classes to the annotation's types or excludes parameter, you cannot include generics. This is a limitation of java. Use private inner interfaces or classes that extend the intended type including the generics parameter to work around this problem.

When passing classes to the annotation, these classes do not need to be supertypes of the field. See the example.

@Delegate cannot be used on static fields or methods.

@Delegate cannot be used when the calculated type(s) to delegate / exclude themselves contain @Delegate annotations; in other words, @Delegate will error if you attempt to use it recursively.