Possible Duplicate:
WHY an Anonymous class in Java can't implement multiple interfaces directly? Simply because of syntax or there is another reason?
Hi all I was wondering why is it that Java anonymous classes couldn’t implement more than one interface?
Like what problems will we have if the Java designers allowed anonymous classes to implement more than one interface?
As such:
IMammal, I4legged anonymous_creature = new IMammal, I4legged() {
{
//..
}
};
anonymous_creature.FourLeggedStuff();
anonymous_creature.MammalStuff();
In Javas type-system there is precisely one static type for each expression. If you had to choose one static type for
anonymous_creatureyou wouldn’t be able to make much use of the variable, which is probably why you wrotewhich actually changes Javas type-system fundamentally. (Possibly it has been excluded for the same reason as multiple inheritance, namely in order to keep the language simple.)
Besides, there is a trivial workaround, and that is to introduce a auxiliary interface extending both of them:
and then do