Change in javac handling of anonymous/local classes

Alex Buckley alex.buckley at oracle.com
Wed Feb 27 14:05:59 PST 2013


On 2/27/2013 1:40 PM, Maurizio Cimadamore wrote:
> On 27/02/13 21:16, Alex Buckley wrote:
>> - I suspect javac 1.6 and 1.7 choose TT.f3(String) because of a
>> different belief about shadowing. Maurizio, please comment on what's
>> visible at 'f3(0);'.
> Javac implements the so called comb-lookup [1] - supertypes are looked
> up before enclosing types. The problem with f1 is a glitch that has been
> fixed in JDK 8.
>
> Afaik the comb rule is also supported in Eclipse. I don't think there's
> any compiler out there that think the anonymous class has two f3 members.
>
> [1] -
> https://blogs.oracle.com/jrose/entry/scope_ambiguities_between_outer_and

First, I didn't say the anonymous class declaration has two f3 members. 
Obviously it has one f3 member, inherited from TT. What I said is that 
two f3 method declarations are _visible_ from the body of the anonymous 
class declaration, at least according to JLS 6.4.1.

Second, the comb rule is operational in nature, and has never been 
stated explicitly in the JLS. It should emerge from a combination of 
class membership and inheritance (8.2, 8.4.8), scope (6.3), shadowing 
(6.4.1), and the meaning of method names (6.5.7.1). I don't think it 
does emerge, though perhaps I am misinterpreting shadowing in 6.4.1. 
It's clear that compilers think X1.f3 in the enclosing scope is shadowed 
by the inherited TT.f3. (Even though no-one actually _likes_ the comb rule.)

Alex



More information about the compiler-dev mailing list