Re: Protected inner classes and inheritance
Piotr Kobzda wrote:
Daniel Pitts wrote:
However, if you make everything public, you can keep
Inner's members are protected from anyone who doesn't inherit from
Not fully protected (see my previous post).
The only inconsistency here is that outer classes can reference
inner classes members, regardless of access modifier. Inner itself
isn't inherited into SecondLevel, only the namespace of the definition
Hmm... I don't get it -- there is no any inconsistency IMHO.
Ah, I see that now! Daniel is talking about inconsistency with general
access rules between the same level outer and inner classes -- which I
completely agree with (don't mind here, how that access is
implemented!). I, by mistake, tried to apply Daniel's point into the
OP's particular case, taking as outer class the SecondLevel class (not
even sure now, if it's legal to call it outer?). So, that part is clear
AIUI, the Inner class is a member of TopLevel class, and as a member
(not a ?namespace?) is inherited by/into the SecondLevel class.
The access modifiers of Inner's members are honored the same way as
for any other language element, regardless of the SecondLevel class
access level to the Inner class.
That's how I see that. Am I missing something?
It's dicey to articulate Java's rules because sometimes we see it as a
strictly compiled language, and sometimes we explicitly acknowledge its
interpretive and reflective capabilities. I was reading the first part
of the thread in terms of javac only, as stated by the OP, wherein
reflection is not relevant.
Sure. However, I'm not really care about reflection here.
Had the topic opened the door to runtime considerations then we'd be in
"yeah, but" territory.
Oh, not really. My confusion expressed here is Java language level related.
For me, each inner class is _a member_ of the class immediately
enclosing it, and just like other members (i.e. fields, and methods), is
inherited by subclasses of that enclosing class.
Daniel said, that inner class is not inherited, and that's what I'm
trying to argue with.