digitalmars.D.learn - Static method of inner class needs this
- rumbu (21/21) Feb 08 2015 class Outer
- wobbles (5/26) Feb 09 2015 In the first case, is there an "Inner" that is visible outside of
- ketmar (5/16) Feb 09 2015 strictly speaking, this is not a bug. compiler doesn't do deep analysis=...
- rumbu (3/6) Feb 09 2015 Thank you, static qualifier works. I thought in C# terms where a
- Steven Schveighoffer (6/22) Feb 09 2015 To expand on this, nested classes (that is, a class nested inside
class Outer { class Inner { static Inner createInner() { return new Inner(); //need 'this' to access member this } } } Is this a bug? If Inner is not nested, it works as expected: class Inner { static Inner createInner() { return new Inner() } } D version: 2.066.1
Feb 08 2015
On Monday, 9 February 2015 at 07:32:33 UTC, rumbu wrote:class Outer { class Inner { static Inner createInner() { return new Inner(); //need 'this' to access member this } } } Is this a bug? If Inner is not nested, it works as expected: class Inner { static Inner createInner() { return new Inner() } } D version: 2.066.1In the first case, is there an "Inner" that is visible outside of "Outer"? If so, the compiler wont know which one your talking about, so need to specify with this.
Feb 09 2015
On Mon, 09 Feb 2015 07:32:32 +0000, rumbu wrote:class Outer { class Inner { static Inner createInner() { return new Inner(); //need 'this' to access member this } } } =20 Is this a bug?strictly speaking, this is not a bug. compiler doesn't do deep analysis=20 on nested structures/classes to determine if they really require context=20 pointer. you can use `static class Inner` to tell the compiler that=20 `Inner` doesn't require any context.=
Feb 09 2015
On Monday, 9 February 2015 at 09:30:55 UTC, ketmar wrote:... you can use `static class Inner` to tell the compiler that `Inner` doesn't require any context.static class means anything else.
Feb 09 2015
On 2/9/15 4:30 AM, ketmar wrote:On Mon, 09 Feb 2015 07:32:32 +0000, rumbu wrote:To expand on this, nested classes (that is, a class nested inside another class) REQUIRE a pointer to the outer class instance (accessed via hidden member outer). The reason for this is Java portability. Seriously :) -Steveclass Outer { class Inner { static Inner createInner() { return new Inner(); //need 'this' to access member this } } } Is this a bug?strictly speaking, this is not a bug. compiler doesn't do deep analysis on nested structures/classes to determine if they really require context pointer. you can use `static class Inner` to tell the compiler that `Inner` doesn't require any context.
Feb 09 2015