<init> and factories
john.r.rose at oracle.com
Fri Oct 18 17:46:59 UTC 2019
On Oct 17, 2019, at 1:38 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> Fine points in the VM prototype:
>> Would there be any restrictions on the contents of a constructor/factory method <new>? (I hope not.)
> I'd be sad if it were possible for a invocation of a `<new>` method to leave a `null` on the stack.
Yes. And should a factory contract sometimes include a guarantee of an exact type for the non-null return value?
(Maybe yes, sometimes no. Probably null is always wrong; don’t call that a factory.)
So this leads to one or two use cases for type operators:
1. Non-null decoration on descriptor. Could be a template specialization NonNull<*C> where
C is the return value and the thing with * is reified. All factories should return this.
(Could be LC//NonNull; or LNonNull//C; or LC[NonNull]; or LNonNull[C]; as a decoration
syntax for descriptors. Various other considerations would determine the actual bike shed color.)
2. Exact-type decoration on descriptor. Could be another template specialization Exact<*C>.
Exact types are sometimes nice to have, although they make API points very rigid. Sometimes
that’s the goal.
More information about the valhalla-spec-observers