Implement Mixin In Java?

Lennie picture Lennie · Feb 25, 2009 · Viewed 31k times · Source

Using Java 6, how can I implement a mixin? It is very easy and possible in Ruby. How can I get similar in Java?

Answer

Daniel Fanjul picture Daniel Fanjul · Feb 26, 2009

You could use CGLIB for that. The class Mixin is able to generate a dynamic class from several interfaces / object delegates:

static Mixin    create(java.lang.Class[] interfaces,
                        java.lang.Object[] delegates)
static Mixin    create(java.lang.Object[] delegates)
static Mixin    createBean(java.lang.Object[] beans)