Nullable!T with T of class type

kdevel kdevel at vogtner.de
Thu Jun 28 19:45:52 UTC 2018


On Thursday, 28 June 2018 at 19:22:38 UTC, Jonathan M Davis wrote:
> Nullable makes sense in generic code, because the code isn't 
> written specifically for them, but something like 
> Nullable!MyClass in non-generic code is pointless IMHO, because 
> a class reference is already nullable.

It is already technically nullable. But how do you signify to the 
reader of the code that a class member in a struct or in a class 
may intentionally (not purely technically) be null?

If I had written

     class R {
        :
        S s;
        :
     }

with S being a class. The reader of the code cannot spot if s is 
optional. In my code I could not have declared S as a struct 
since it implements an interface.


More information about the Digitalmars-d-learn mailing list