Community
Participate
Working Groups
public class Outer extends BaseClass { static class Inner extends ClassWithAMethodCalledFoo { void bar(){ foo();//COMPILER COMPLAINS THAT THIS IS AMBIGUOUS. } } void foo(){} } Note that Outer.this.foo() is not really visible because there is no enclosing instance with which Inner could call Outer's foo. Yet, the compiler says it is ambiguous.
This seems to be a compliance problem. If you are compiling such a code with a JDK 1.3.x compiler, it will complain as well. If you compile with a 1.4 compiler, it doesn't complain. Our compiler has two compliance modes. If you compile such a senario with -1.3 (compliance 1.3), it complains that there is an ambiguity. But if you compile with -1.4 (compliance 1.4), it doesn't complain. The compliance can be set on the compiler preference page. Does it work for you if you set the compliance to 1.4?
I have refactored my code already to remove this inner class, so I can't test it right now. I knew it seemed strange. At least the 1.4 compiler spec is "smarter". I'm closing.
This is the intended behavior. With 1.4 compliance, inherited members will prevail against enclosing ones. In 1.3 mode, we had to find ambiguities in order to pass JCK tests. The new behavior is following the JLS 1.2, and shouldn't change (I hope).
This really isn't an ambiguous call. It is a falsely reported ambiguity. If I try to call Outer.this.foo(), I get an error saying there is no enclosing instance because the inner class is *static*. I understood from the first response that reporting this false ambiguity was required to pass 1.3 compatibility tests. Now it sounds as though you are saying that in 1.4 the ambiguity is handled by preferring the inherited method. Is this for static inner classes, or both static and instance?