Annotation Type Self


  • @Retention(RUNTIME)
    @Target({TYPE_USE,METHOD})
    public @interface Self
    Annotate a method return type, parameter type, or a field type with @Self to achieve Self type behavior.

    Note the ElementType.METHOD target is for internal use only. This is necessary for generated code where even though the code applies the Self annotation at the method return type position Java 8 misinterprets it as a Method annotation, hence the METHOD target here. The METHOD target type will be removed in a future release.

    See the Self Type documentation for more information.

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean value
      value is exclusive to array extension methods.
    • Element Detail

      • value

        boolean value
        value is exclusive to array extension methods. Setting to true accesses the array's core component type instead of the array type itself. E.g.,
           public class MyArrayExtension {
           public static List<@Self(true) Object> toList(@This Object array) {
             return Arrays.asList((Object[])array);
           }
         
        Default:
        false