Null references redux

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Sep 26 15:18:35 PDT 2009


On Sat, Sep 26, 2009 at 6:10 PM, Walter Bright
<newshound1 at digitalmars.com> wrote:
> Jarrett Billingsley wrote:
>>
>> It wouldn't. The compiler wouldn't allow it. It would force you to
>> initialize it. That is the entire point of nonnull references.
>
> Initialize it to what?
>
> A user-defined default object? What should happen if that default object is
> accessed? Throw an exception? <g>

The point of using a nonnull type is that you *never expect it to be
null ever*. So you would be initializing it to some useful object. If
you *want* null, you'd use a nullable reference.

> How would you define an "empty" slot in a data structure?

A nullable reference.



More information about the Digitalmars-d mailing list