Skip navigation
2010

Carlo de Wolf's Blog

September 2010 Previous month Next month

As an experiment I've created a Mixin utility class which allows for multiple inheritance. Well actually it does what the class is named create a mixin based on multiple interfaces.

 

I've no real use case for it, it's a bit of brain rot that I just wanted committed somewhere.

 

So here is a piece of code that makes use of the Mixin:

public class MixinTestCase
{
   public static interface A
   {
      String getA();
   }
 
   public static interface B
   {
      String getB();
   }
 
   @Test
   public void test1()
   {
      A a = new A() {
         @Override
         public String getA()
         {
            return "A";
         }
      };
 
      B b = new B() {
         @Override
         public String getB()
         {
            return "B";
         }
      };
 
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      Object mixin = Mixin.newProxyInstance(loader, a, b);
 
      assertEquals("A", ((A) mixin).getA());
      assertEquals("B", ((B) mixin).getB());
   }
}

 

The full code can be found here: http://github.com/wolfc/jboss-beach-lang