7
votes

Exemple de mixin de cglib

Quelqu'un peut-il me donner un bon exemple pour java cglib Mixin Utilisation de classe? J'ai creusé sans aucun d'entre eux semble assez simple.


0 commentaires

3 Réponses :


0
votes

Cet exemple fonctionnent avec un activateur avancé et fonctionnent comme Mixin: http://www.jroller.com/melix/entry/alternative_to_delegate_pattern_with


0 commentaires

8
votes

Assez facile:

import static org.junit.Assert.*;
import net.sf.cglib.proxy.Mixin;

import org.junit.Before;
import org.junit.Test;


public class MixinTest {

    @Test
    public void test() {
        Mixin mixin = Mixin.create(new Object[]{ new Class1(), new Class2() });
        assertEquals(1, ((Interface1)mixin).method1());
        assertEquals(2, ((Interface2)mixin).method2());
    }

    private interface Interface1 {
        public int method1();
    }

    private interface Interface2 {
        public int method2();
    }

    private static class Class1 implements Interface1 {

        @Override
        public int method1() {
            return 1;
        }

    }

    private static class Class2 implements Interface2 {

        @Override
        public int method2() {
            return 2;
        }

    }

}


0 commentaires

1
votes

La question est plus large que la seule affaire de mixage de bases d'interface, voici l'exemple de la mixine de cglib avec 2 classes arbitraires: xxx


0 commentaires