@Documented @Retention(value=RUNTIME) @Target(value=PARAMETER) public @interface DelegatesTo
This annotation can also be used to help the type checker (TypeChecked
)
which would not report errors then if the delegate is of the documented type. Of course, it is
also compatible with CompileStatic
.
Example:
// Document the fact that the delegate of the closure will be an ExecSpec ExecResult exec(@DelegatesTo(ExecSpec) Closure closure) { ... }
Modifier and Type | Optional Element and Description |
---|---|
int |
genericTypeIndex
The index of the generic type that will be the type of the closure's delegate.
|
int |
strategy
The
Closure.resolveStrategy used by the closure. |
String |
target
In cases when there are multiple
@DelegatesTo.Target annotated parameters, this
member should be set to the DelegatesTo.Target.value() of the correct target. |
String |
type
The type member should be used when the type of the delegate cannot
be represented with
value() , genericTypeIndex() or
target() . |
Class |
value |
public abstract Class value
public abstract int strategy
Closure.resolveStrategy
used by the closure.public abstract int genericTypeIndex
@DelegatesTo.Target
annotated
parameter for this usage, with the index starting at 0.public abstract String target
@DelegatesTo.Target
annotated parameters, this
member should be set to the DelegatesTo.Target.value()
of the correct target.public abstract String type
value()
, genericTypeIndex()
or
target()
. In this case, it is possible to use a String to represent
the type, at the cost of potential uncaught errors at compile time if the
type is invalid and increased compile time.