Package: groovy.lang

## [Java] Annotation Type DelegatesTo

- groovy.lang.DelegatesTo

-     @Documented
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.PARAMETER)
      public @interface DelegatesTo

  This annotation can be used by API or DSL writers to specify what the delegate type of a closure will be. This is important for IDE support.

  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:

       // Declare that the delegate of the closure will be an ExecSpec
       ExecResult exec(@DelegatesTo(ExecSpec) Closure closure) { ... }

  Since:
    2.1.0

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `@interface` | `DelegatesTo.Target` | Specifies the delegate for a `@DelegatesTo` annotated parameter of the same method.

  - ### Element Summary

    Optional Element Summary
    Type | Name and Description
    --- | ---
    `int` | `genericTypeIndex` The index of the generic type that will be the type of the closure's delegate.
    `int` | `strategy` The closure's resolve strategy.
    `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 by value() or target().
    `Class` | `value` The closure's delegate type, if not using `DelegatesTo.Target` or type().

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Element Detail

    - #### public int genericTypeIndex

      The index of the generic type that will be the type of the closure's delegate. The generic types are considered with respect to the `@DelegatesTo.Target` annotated parameter for this usage, with the index starting at 0.

      Default:
        -1

    - #### public int strategy

      The closure's resolve strategy.

      See Also:
        Closure.DELEGATE_FIRST
        Closure.DELEGATE_ONLY
        Closure.OWNER_FIRST
        Closure.OWNER_ONLY
        Closure.TO_SELF
      Default:
        Closure.OWNER_FIRST

    - #### public 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.

      Default:
        ""

    - #### public String type

      The type member should be used when the type of the delegate cannot be represented by value() or target(). In this case, it is possible to use a string to represent the type, at the cost of more compile time and potential uncaught load errors if the type is invalid.

      Since:
        2.4.0
      Default:
        ""

    - #### public Class value

      The closure's delegate type, if not using `DelegatesTo.Target` or type().

      Default:
        DelegatesTo.Target.class