Thread overview |
---|
June 09, 2005 Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
I'm trying out the new anonymous nested classes, and can't figure out why this won't compile: public interface Iterator { public bool moveNext(); public Object current(); } public class Stack { public Iterator interator() { return new class Iterator { public this() { currentIndex_ = items_.length - 1; // error here: this for items_ needs to be type Stack not type void* } public bool moveNext() { return currentIndex_ >= 0; } public Object current() { return items_[currentIndex_]; // error here: this for items_ needs to be type Stack not type void* } private int currentIndex_; }; } private Object[] items_; } The anonymous class (which inherits from Iterator) should have access to its enclosing class's members. Or have I gone bonkers? |
June 09, 2005 Re: Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | > return new class Iterator { I think this is supposed to be something like: # return new class :Iterator { > public this() { > currentIndex_ = items_.length - 1; > // error here: this for items_ needs to be type Stack not type void* > } I have no clue... Probably something odd about the way anonymous classes are implemented. Might try using something like 'Stack.items_' but I would expect that to be treated as a static referance. Maybe 'this.outer.items_' or something therelike will become available. -- Chris Sauls |
June 09, 2005 Re: Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sauls | "Chris Sauls" <ibisbasenji@gmail.com> wrote in message news:d8a67b$264i$1@digitaldaemon.com... >> return new class Iterator { > I think this is supposed to be something like: > # return new class :Iterator { > >> public this() { >> currentIndex_ = items_.length - 1; >> // error here: this for items_ needs to be type Stack not >> type void* >> } > I have no clue... Probably something odd about the way anonymous classes are implemented. Might try using something like 'Stack.items_' but I would expect that to be treated as a static referance. Maybe 'this.outer.items_' or something therelike will become available. > > -- Chris Sauls Doesn't work, sadly. Since the point was to ease translation of Java code, I thought returning anonymous classes would be possible, as it is in Java. Looks like it's not. Has anyone else sussed this out yet? Perhaps an example in the spec is in order. |
June 10, 2005 Re: Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | It's a compiler bug. I need to get it fixed. |
June 23, 2005 Re: Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | In article <d8d2gp$20ea$1@digitaldaemon.com>, Walter says... > >It's a compiler bug. I need to get it fixed. > > Sorry, I don't see how DMD 0.127 really fixes that, it still errs (now complaining, that items_ is not accessible). How to make that code compilable (other than making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) Kind regards, Stefan |
June 23, 2005 Re: Anonymous nested classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | In article <d8d2gp$20ea$1@digitaldaemon.com>, Walter says... > >It's a compiler bug. I need to get it fixed. > > Sorry, I don't see how DMD 0.127 really fixes that, it still errs (now complaining, that items_ is not accessible). How to make that code compilable (other than making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) Kind regards, Stefan |
June 23, 2005 Sorry for the double post | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan | In article <d9fce8$gcs$1@digitaldaemon.com>, Stefan says... > >In article <d8d2gp$20ea$1@digitaldaemon.com>, Walter says... >> >>It's a compiler bug. I need to get it fixed. >> >> > >Sorry, >I don't see how DMD 0.127 really fixes that, it still errs (now complaining, >that items_ is not accessible). How to make that code compilable (other than >making items_ public). Sorry if this is a dumb question, i'm a D newbie ;) > >Kind regards, >Stefan > Sorry for double posting. Seem to have hitten the post button twice :-( |
Copyright © 1999-2021 by the D Language Foundation