Annotation Interface Mixin


@Target(TYPE) @Retention(RUNTIME) public @interface Mixin
Annotation to designate a class as a mixin class. The fields and methods from the mixin class will be added to the target types. The target types can include interfaces, in which case the annotated class will be mixed in to all classes which implement any of those interfaces.

If the mixin class implements any interfaces, those interfaces will be added to the target types. This is the recommended way to access methods that are mixed in to the target types.

Constructors are not mixed in to the target types, but a single method in the mixin class can be annotated with @MixinInit and this will be called exactly once at some point during the construction of each target type (to be precise, it is called at the end of each target type constructor that doesn't cascade to another constructor in the same type).

It's important to note that inline field initializers in the mixin class will not get added to the target types (since at the bytecode level they are be part of the mixin constructor), so field initializers must be placed in the @MixinInit.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Element Details