> That's correct (Torkel's example notwithstanding... in Torkel's cose, he
> is overriding an inner class that's inherited into the class where he
> extends it, so it's not really subclassing another class's inner
> class.)
> > That's correct (Torkel's example notwithstanding... in Torkel's cose, he
> > is overriding an inner class that's inherited into the class where he
> > extends it, so it's not really subclassing another class's inner
> > class.)
>
> True (reading "hiding" for "overriding").
Actually, read "subclassing" for "overriding". Sorry about that; my
mistake.
> But what would it mean to
> subclass another class's inner class? You have to get a surrounding
> instance from somewhere.
Yes. The syntax would have to provide a means to specify separate
enclosing instances for the superclass and the subclass. With anonymous
inner classes, there is such a mechanism: the enclosing instance for the
anonymous subclass is 'this', while the enclosing instance for the
superclass is specified as a qualifier for the "new" expression. There
is no such obvious syntax for named inner classes, so I understand why
the language doesn't provide the ability.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Torkel Franzen - 15 Jan 2006 19:58 GMT
> Actually, read "subclassing" for "overriding".
Yes, of course, the inherited inner class wasn't hidden in my
example.
Mike Schilling - 16 Jan 2006 01:45 GMT
> Yes. The syntax would have to provide a means to specify separate
> enclosing instances for the superclass and the subclass.
Would it? Perhaps I misunderstand the suggestion, but I thought it was to
be able to modify the behavior of an existing inner class, giving both the
same enclosing instance, much like
class Outer
{
class InnerSuper
{
}
class InnerSub extends InnerSuper
{
}
}
but with InnerSub defined in a different file.
Chris Smith - 16 Jan 2006 05:40 GMT
> Would it? Perhaps I misunderstand the suggestion, but I thought it was to
> be able to modify the behavior of an existing inner class, giving both the
[quoted text clipped - 12 lines]
>
> but with InnerSub defined in a different file.
Right, but there are implications to InnerSub being in a different file.
It is, therefore, in a different top-level class... and assuming it's an
inner class (which was part of the original description), it must have
an enclosing instance of that top-level class.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Mike Schilling - 16 Jan 2006 18:03 GMT
>> Would it? Perhaps I misunderstand the suggestion, but I thought it was
>> to
[quoted text clipped - 16 lines]
>
> Right, but there are implications to InnerSub being in a different file.
Again, I thought the suggestion was to get around those implications.
Piotr Kobzda - 16 Jan 2006 10:45 GMT
> There
> is no such obvious syntax for named inner classes, so I understand why
> the language doesn't provide the ability.
Java language does.
class A {
class Inner {
}
}
A a = new A();
A.Inner ai = a.new Inner() {}; // anonymous subclass of inner class
class AInnerSubclass extends A.Inner { // non-anonymous one
AInnerSubclass(A a) {
a.super();
}
}
ai = new AInnerSubclass(a);
Regards,
piotr
Torkel Franzen - 16 Jan 2006 10:59 GMT
> class AInnerSubclass extends A.Inner { // non-anonymous one
> AInnerSubclass(A a) {
> a.super();
> }
> }
True, you can supply an enclosing instance in the constructor. This
simply didn't occur to me. It's rather remarkable that the compiler
can figure this out.
daniel.w.gelder@gmail.com - 16 Jan 2006 15:24 GMT
class A {
class Inner {
}
}
A a = new A();
A.Inner ai = a.new Inner() {}; // anonymous subclass of inner class
class AInnerSubclass extends A.Inner { // non-anonymous one
AInnerSubclass(A a) {
a.super();
}
}
This simply doesn't work. The compiler generates an error for the
reason that A.Inner is not accessible here; there is no enclosing
instance. And there isn't. (Which A is AInnerSubclass going to refer to
when it asks for A.this?)
Torkel Franzen - 16 Jan 2006 15:51 GMT
> This simply doesn't work.
This compiles just fine:
class A{
class B{
}
}
class C extends A.B{
C(A a){
a.super();
}
}
The interesting thing is that the compiler actually ponders the body
of the constructor in C to make sure that an enclosing instance is
provided.
Piotr Kobzda - 16 Jan 2006 17:06 GMT
> class A {
> class Inner {
[quoted text clipped - 12 lines]
>
> This simply doesn't work.
It does, simply... copy and paste my example into main() method, then
show compilation errors here (if any).
> The compiler generates an error for the
> reason that A.Inner is not accessible here; there is no enclosing
> instance. And there isn't.
My example is very simple and it will not solve all your problems...
sorry. You have to follow other Java "rules", even in this case...
> (Which A is AInnerSubclass going to refer to
> when it asks for A.this?)
None. In my example A is not the enclosing class of AInnerSubclass, than
A.this is simply not allowed. You can access the enclosing instance of
type A referring it as final variable or storing (e.g. as field) the
instance of A passed to AInnerSubclass constructor.
A.this would be allowed in the context of AInnerSubclass only if there
were class A enclosing it.
BTW, this is quite interesting feature of Java allowing single instance
of inner class to have many instances of enclosing classes. Of course,
you can simply forget about it, if you don't need this feature... '-)
Regards,
piotr
Chris Smith - 16 Jan 2006 18:19 GMT
> class AInnerSubclass extends A.Inner { // non-anonymous one
> AInnerSubclass(A a) {
> a.super();
> }
> }
Learn something every day. Hmm.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation