Inner classes question
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Mon Sep 11 10:36:10 PDT 2006
Ary Manzana wrote:
>
> In Java it's done this way:
>
> class O
> {
> class I1
> {
> }
> class I2
> {
> this()
> {
> I1 a = O.this.new I1;
> }
> }
> }
>
> "O.this" says "Give me the reference of O that contains me" and from
> that point you say "new I1", that belongs to O. The syntax is a bit (a
> lot?) strange, though...
Yeah, maybe it is a little strange but I wouldn't mind if D did it that
way, just that it works.
>
> However, if there is no ambiguity in "new I1", then writing "O.this" is
> not necessary. So the example you sent works perfectly in Java, and I
> think it should work the same way in D.
It would be nice.
The current workaround I'm using can hardly be called a workaround at all:
O outerO;
class O
{
this()
{
outerO = this;
}
class I1
{
}
class I2
{
this()
{
I1 a = outerO.new I1;
}
}
}
The only problem with this is that I am limited to only one instance of
O this way :)
More information about the Digitalmars-d-learn
mailing list