Non-null objects, the Null Object pattern, and T.init
Timon Gehr
timon.gehr at gmx.ch
Thu Jan 16 22:20:34 PST 2014
On 01/17/2014 02:42 AM, Andrei Alexandrescu wrote:
>
> class Widget
> {
> private int x;
> private Widget parent;
> this(int y) { x = y; }
> ...
> // Here's the interesting part
> static Widget init = new Widget(42);
> }
>
> Currently the last line doesn't compile, but we can make it work if the
> respective constructor is callable during compilation. The compiler will
> allocate a static buffer for the "new"ed Widget object and will make
> init point there.
immutable(Widget) iwidget; // ?
More information about the Digitalmars-d
mailing list