Thread overview | |||||
---|---|---|---|---|---|
|
January 02, 2007 "Class.this" equivalent ? | ||||
---|---|---|---|---|
| ||||
All, How can I access a reference to an enclosing class in D? ... something similar to the following Java code: class A { class B { A ref; B() { ref = A.this; } } } |
January 02, 2007 Re: "Class.this" equivalent ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dan | Dan wrote:
> All,
>
> How can I access a reference to an enclosing class in D? ... something similar
> to the following Java code:
>
> class A {
> class B {
> A ref;
> B() { ref = A.this; }
> }
> }
You can use the *outer* keyword to access the class wrapping a nested class.
Like:
class Outer
{
class Inner
{
Outer foo()
{
return this.outer;
}
}
void bar()
{
Inner i = new Inner;
assert(this == i.foo());
}
}
|
January 02, 2007 Re: "Class.this" equivalent ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexander Panek | == Quote from Alexander Panek (a.panek@brainsware.org)'s article
> Dan wrote:
> > All,
> >
> > How can I access a reference to an enclosing class in D? ... something similar to the following Java code:
> >
> > class A {
> > class B {
> > A ref;
> > B() { ref = A.this; }
> > }
> > }
> You can use the *outer* keyword to access the class wrapping a nested class.
> Like:
> class Outer
> {
> class Inner
> {
> Outer foo()
> {
> return this.outer;
> }
> }
> void bar()
> {
> Inner i = new Inner;
> assert(this == i.foo());
> }
> }
Thanks.
--Dan
|
Copyright © 1999-2021 by the D Language Foundation