Annotation Type link


  • @Target(FIELD)
    @Retention(RUNTIME)
    public @interface link
    Use @link to automatically transfer calls on unimplemented interface methods to fields in the same class.
    • Choose between call forwarding and true delegation with @part
    • Override linked interface methods, optionally using part classes (solves the Self problem)
    • Share super interface implementations (solves the Diamond problem)
    • Configure class implementation dynamically
    Classes and links are many-to-many: Many of a class's interfaces may be linked to a single field. A single class may have many linked fields.

    Basic usage

    
     class MyClass implements MyInterface {
       @link MyInterface myInterface; // transfers calls on MyInterface to myInterface
    
       public MyClass(MyInterface myInterface) {
         this.myInterface = myInterface; // dynamically configure behavior
       }
     }
     
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      Class<?>[] share
      Where interface overlap exists with other links, this list of interfaces resolves which links to use.
      boolean shareAll
      If true, indicates this link is shared where interface overlap exists with other links.
      Class<?>[] value
      Specify interfaces to link.
    • Element Detail

      • value

        Class<?>[] value
        Specify interfaces to link. This value overrides the declared type of the field. If no interfaces are specified (default), the linked interfaces are derived from the field's declared type.
        Default:
        {}
      • share

        Class<?>[] share
        Where interface overlap exists with other links, this list of interfaces resolves which links to use. Otherwise, overlapping interfaces are not linked and the class must implement them directly, or it must be declared abstract. If two or more links declare to share the same interface, a compiler error results.
        Default:
        {}
      • shareAll

        boolean shareAll
        If true, indicates this link is shared where interface overlap exists with other links. Similar to share(), but includes all interfaces from this link that overlap.
        Default:
        false