nested class inheritance

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Sat Jul 14 02:45:38 PDT 2012


On Sat, Jul 14, 2012 at 1:36 PM, Guillaume Chatelet <
chatelet.guillaume at gmail.com> wrote:

> On 07/13/12 21:41, Andrei Alexandrescu wrote:
> > On 7/13/12 3:36 PM, Gor Gyolchanyan wrote:
> >> The initial question was: why does DMD 2.059 reject this if this makes
> >> sense?
> >> It's not even a new feature. It's a (possibly) new (and apparently
> >> sensible) use case of an existing feature.
> >
> > I think the simple answer is there was no provision for it. The feature
> > copies the Java feature, and I don't think Java has something like what
> > you defined.
> >
> > Andrei
> >
>
> class Fruit {
>     class Seed {
>     }
> }
>
> class Apple extends Fruit {
>     class AppleSeed extends Fruit.Seed {
>         Apple getOuter() {
>             return Apple.this;
>         }
>     }
> }
>
> class Main {
>     public static void main(String[] args) {
>         final Apple apple = new Apple();
>         final Apple.AppleSeed appleSeed = apple.new AppleSeed();
>         assert (appleSeed instanceof Fruit.Seed);
>         assert (apple == appleSeed.getOuter());
>         assert (appleSeed.getOuter() instanceof Apple);
>         assert (appleSeed.getOuter() instanceof Fruit);
>     }
> }
>
> This is valid Java code actually and I agree with Gor I would have
> expected it to work with D.
>
> Guillaume
>

I didn't even know this worked in Java. This means, that nested classed in
D can't translate nested classed in Java after all.

-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120714/432bfab0/attachment.html>


More information about the Digitalmars-d mailing list