Unexpected behavior when changing the modifier of a member variable in connection with an inner class
Lars Herschke
lhersch at dssgmbh.de
Wed May 6 07:35:55 UTC 2020
Hello Jesper,
thanks a lot. The reference in the oracle-doc is exactly what I was
looking for. I don't write a tool. I debugged a piece of software that
did not behave as expected. The problem was precisely with the modifier.
Jesper Steen Møller schrieb:
> Hi Lars
>
> I'm not sure we're entirely on topic here, but I couldn't resist:
>
> Are you preparing a puzzler talk, or writing a compiler or other
> semantic tool? ;-)
>
> The detail is
> in https://docs.oracle.com/javase/specs/jls/se14/html/jls-8.html#jls-8.2.
>
> In "Inner", only one x is visible, namely Outer.this.x. The private x is
> not inherited into Inner, as per §8.2 "Members of a class that are
> declared |private| are not inherited by subclasses of that class."
>
> In "Inner", both y's are visible and this.y is the closest one, i.e. the
> one inherited from Outer, qualified as Outer.Inner.this.y. You can still
> access the other y, by using Outer.this.y.
>
> Hope this "helps".
>
> -Jesper
>
> BTW, IMHO: While name inhertance and scope rules are tricky for members,
> they're mind-boggling for type names, at least for my mind.
>
>
More information about the discuss
mailing list