Walter Bright 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>
How would you define an "empty" slot in a data structure?
You can allow a non-nullable reference to be null, just like you allow
an immutable object to be mutable during construction.
You just have to make sure the non-nullable reference is definitely
assigned.