Re: Why Generics?



Mike Schilling wrote:

> > Perhaps you could require a cast before using a nullable type ?
> >
> > Nullable%Object a;
> > ...
> > a.toString(); // error
> > ...
> > Object ann = (Object)a;
> > ann.toString() // ok
>
> Sure, but this doesn't accomplish as much; it simply raises an exception
> when a reference is unexpectedly null, exactly the way Java does today,
> rather than madate (or at least encourage) code that processes a null
> correctly.

Fair point.

Though you /could/ make it throw a checked NullCastException or something like
that.

Just out of curiosity, would you like to see some sort of compile-time null
check added to the type system ?

-- chris



.



Relevant Pages

  • Re: DBNULL to DATETIME
    ... One of its fields is a DateTime type field. ... What can I do to cast it? ... nullable type. ... Then when reading you would want to check to make sure it has a value ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to get value of nullable of unknown type??
    ... or any other nullable type. ... of the nullable without knowing its type. ... It's not clear to me what sort of interface you'd be looking to use ...
    (microsoft.public.dotnet.framework)