static class

Jonathan M Davis jmdavisProg at gmx.com
Sun Feb 17 15:52:11 PST 2013


On Sunday, February 17, 2013 23:26:37 Ben Davis wrote:
> On 17/02/2013 22:25, Jonathan M Davis wrote:
> > However, non-static nested classes are associated with an instance of the
> > outer class, and therefore only one can exist per class instance.
> 
> That's not true, is it? You can make as many nested instances as you
> like. It's just that there must be some outer instance available at the
> time of construction (which can be a new one each time or the same one
> every time or anything in between).

I stand corrected (I just looked it up again in TDPL). I don't think that I've 
ever used a non-static inner class in D. I think that used them in Java all of 
once, but that was quite some time ago, so I don't remember for certain. It's 
not exactly the most useful feature ever. So, clearly I misremembered.

> Is it possible to write someInstanceOfR.outer? I've occasionally wanted
> Java to have that feature, and ended up storing the 'outer' reference
> manually. Though this probably means I was writing bad code; I can't
> remember. :D

Probably. I don't know. It's not a feature that I ever use.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list