Nullable with reference types

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 29 14:26:35 PDT 2015


On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote:
> Hi, everyone.
>
> ```
> import std.typecons : Nullable;
>
> class Test {}
>
> Nullable!Test test;
> assert(test.isNull);
> ```
>
> Why does `Nullable` allowed to be used with reference types 
> (e.g. classes)?
>
> P.S. I have experience with C#, where `Nullable<T>` cannot be 
> used with reference types. And it sounds logical to me.

It does feel wrong but there is another feature of Nullable where 
you can define the value of null. Which might be handy in some 
cases where you don't want a reference type to actually be null? 
I don't know if this is the case but it may be useful.


More information about the Digitalmars-d-learn mailing list