Nullable!T

Adam Ruppe destructionator at gmail.com
Tue Jul 6 12:05:55 PDT 2010


On 7/6/10, Nick Sabalausky <a at a.a> wrote:
> But ducks are bad.

Oh, I don't know. You don't want to over do it, but to me a nullable
thing is just anything where item = null; compiles; a good fit for a
duck.

> How about an INullable that's implemented by Nullable and
> implicitly implemented by classes?

A problem here is if the class is null, you won't be able to use it. Consider:

interface INullable {
    bool isNull();
}

class Whatever : INullable {
    bool isNull() { return this is null; }
}

void main() {
    Whatever a;
     if(a.isNull()) // hardware exception, since this is null, it
can't get at the interface
}


> (That's one thing I like about C# - it
> uses nice safe explicit interfaces instead of compile-time duck-typing.)

Yea, there is a nice benefit there, but in this specific case, I don't
think it can be done due to the nature of null.


More information about the Digitalmars-d mailing list