I guess you are aware of the fact that cglib cannot make multiple inheritence happen in Java. All that cglib does is creating a proxy class which implements all the methods and all the interfaces found on any (super)class that is added to the Mixin
generator. Note that the super class of the proxy will still Object
.
Since you are adding two classes C
and B
which both inherit from class A
which implements interface I
, this interface will be added twice to the implementing proxy. However, this is not allowed in Java and the verifier will complain about it when the class is loaded. The idea of cglib is: I create a new class implementing n
interfaces and you provide me n
feedback classes with methods of the same signature to which these calls will be mapped. You defined a mapping equivalent to:
I
toB
I
toC
But how could cglib solve this problem? It could implement interface I
only once. However, since the Mixin
works by delegating any interface method calls to its registered feedback objects, thiis would not help much. Should this feedback object be the instance of B
or of C
that you provided? Cglib cannot decide this for you, even though it should of course give you a better error message over this ambiguity instead of plainly following the protocol.
By the way, you are using the internal cglib Mixin.Generator
for your purposes. You are officially supposed to use the public Mixin#create(Class<?>[], Object[])
method. I wrote a little bit on how to use cglib, if you are interested. Also, the official API allows you to decide which interface is mapped to which feedback object. Furthermore, it allows you to add additional, unmapped interfaces to implement such that your proxy can be casted to this type.