Value types, encapsulation, and uninitialized values

Doug Lea dl at
Sun Oct 28 12:11:49 UTC 2018

Sorry for even slower response...

On 10/11/18 10:14 AM, Brian Goetz wrote:
> Except, the current story falls down here, because authors must content
> with the special all-zero default value, because, unlike classes, we
> cannot guarantee that instances are the result of a constructor.

Can we enumerate the cases where this is encoutered? The main one is:

If a value class does not have a no-arg constructor, why not disallow
array construction (dynamically if necessary), but also supply special
methods such as createAndFillArray(int size, T proto) and a few others
to still allow safe array construction when it applies.

In most cases where not-yet-present is a common case, one would think
that people would choose to make T an Object type or use Optional<T>
rather than using a pure value type.


More information about the valhalla-spec-observers mailing list