nested class inheritance
Paulo Pinto
pjmlp at progtools.org
Sat Jul 14 04:05:53 PDT 2012
Am 14.07.2012 11:45, schrieb Gor Gyolchanyan:
> On Sat, Jul 14, 2012 at 1:36 PM, Guillaume Chatelet
> <chatelet.guillaume at gmail.com <mailto: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.
>
This usually comes up in certification and interview questions.
More information about the Digitalmars-d
mailing list