Object obj = Enhancer.create(Object.class, new Class[]{ DI1.class, DI2.class }, callback); assertTrue(((DI1)obj).herby().equals("D1")); assertTrue(((DI2)obj).derby().equals("D2"));
Callback[] callbacks = new Callback[]{ new Dispatcher() { public Object loadObject() { return impls[0]; } }, new Dispatcher() { public Object loadObject() { return impls[1]; } } };  Enhancer e = new Enhancer(); e.setInterfaces(new Class[]{ Foo.class, Bar.class }); e.setCallbacks(callbacks); e.setCallbackFilter(new CallbackFilter() { public int accept(Method method) { return (method.getDeclaringClass().equals(Foo.class)) ? 0 : 1; } }); Object obj = e.create();  assertTrue(((Foo)obj).foo().equals("foo1")); assertTrue(((Bar)obj).bar().equals("bar1"));  impls[0] = new Foo() { public String foo() { return "foo2"; } }; assertTrue(((Foo)obj).foo().equals("foo2"));
    public void testSimple() throws Exception {        final Map map = new HashMap();        map.put(DI1.class.getName(), new D1());        map.put(DI2.class.getName(), new D2());        Dispatcher callback = new Dispatcher() {            public Object loadObject(String className) {                return map.get(className);            }        };        Object obj = Enhancer.create(Object.class,                                     new Class[]{ DI1.class, DI2.class },                                     callback);        assertTrue(((DI1)obj).herby().equals("D1"));        assertTrue(((DI2)obj).derby().equals("D2"));    }