interface @Mixins

The @Mixins annotation is for Composites and MixinTypes. It declares which implementation classes should be used for the found MixinTypes. Implementations for the same MixinType is allowed, and used for overriding purposes. The nearer to the Composite root the higher the precedence.

Description

The @Mixins annotation is central to the composition of the Composite. It will declare exactly which Mixins to use in the Composite, as well as the precedence of Mixin method overrides.

The Mixins will be evaluated from left-to-right as they are declared within the @Mixins annotation, and the each super interface will be scanned likewise. It is also possible to declare Mixins on Mixin implementation classes, typically to declare private Mixins needed by a Mixin. The @Mixins declared on Mixin implementations will be evaluated after the @Mixin declarations in the interfaces.

Precedence means that the first Mixin implementation found to satisfy a MixinType method will be used. Interfaces are searched before classes and Mixins implementing the MixinType will be selected before GenericMixins.

Declaration

package org.qi4j.api.mixin;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation is used in composites to
* declare mixin implementation classes.
* <p/>
* Mixins tells the runtime which implementation
* class of a Mixin should be used.
* The &#64;Mixins annotation can occur at any
* level in the composite hierarchy
* and the runtime will match each found
* Mixin implementation against a Mixins annotation.
* All mixin interfaces must have a Mixin
* implementation in the composite hierarchy or
* a runtime exception will occur.
* <p/>
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )
@Documented
public @interface Mixins
{
    Class<?>[] value();
}

Example

@Mixins( { MyStuff.class, PropertyMixin.class } )
public interface MyStuffComposite extends Composite, MyStuff, OtherStuff
{}

public interface MyStuff
{
    void doStuff();
}

public interface OtherStuff
{
    Property<String> stuff();
}

public class MyStuffMixin
    implements MyStuff
{
    public void doStuff()
    {
        // impl code goes here.
    }
}


Qi4j and the Qi4j logo are trademarks of Richard Öberg, Niclas Hedhman and the members of the Qi4j Core Team. See Qi4j licensing for more information.
Powered by SiteVisionexternal link.