defaultvalue and enclosing instances

John Rose john.r.rose at oracle.com
Fri Sep 14 16:05:24 UTC 2018


On Sep 14, 2018, at 1:32 AM, Srikanth <srikanth.adayapalam at oracle.com> wrote:
> 
> Some options seem to be: (a) disallow InnerValue.default syntax

That won't work, because taking away the T.default syntax doesn't
take away the ability to get default values.  T.default == (new T[1])[0].

> if InnerValue is a nonstatic nested class and mandate that instances of such be created using CCN (b) allow InnerValue.default only where an implicit instance is available and somehow arrange for the proper initialization of the enclosing instance

See above:  T.default exists because you can always get a default instance,
one way or another, and so there's no point trying to hide the fact.

> (c) Allow for explicit enclosing instance to be specified in the syntax itself and somehow arrange for the proper initialization of the enclosing instance

This suggestion is just the RFE of user-defined defaults in a different wrapper.
We won't be doing that RFE, because of the systemic cost and poor return.

> ... (d) other solutions ...

The simplest one comes to mind:  Allow T.default to have a default up-reference
of null, as a special case for inner values.  Referring to the outer instance from
a default inner instance will thus fail with NPE.  "It hurts when I do this, Doctor"
"Then don't do that."

— John


More information about the valhalla-dev mailing list