> From: "Brian Goetz" <brian.go...@oracle.com>
> To: "Remi Forax" <fo...@univ-mlv.fr>
> Cc: "Dan Heidinga" <heidi...@redhat.com>, "Kevin Bourrillion"
> <kev...@google.com>, "valhalla-spec-experts"
> <valhalla-spec-experts@openjdk.java.net>
> Sent: Monday, April 25, 2022 9:54:26 PM
> Subject: Re: [External] Foo / Foo.ref is a backward default; should be 
> Foo.val /
> Foo

>> This seems very specific to Optional, for Optional storing null is always a
>> mistake, but that's not true for other VBC, by example a deadline can be 
>> typed
>> as an Instant with null meaning no deadline.

> No, it is not specific to Optional at all. Many domains exclude null on an
> ad-hoc basis.

> It is about giving the user the choice to reserve space in the heap for the 
> null
> or not. If other logic has already excluded null (which is common), they can
> use an Instant.val and get better footprint. If they like the semantics of
> having null, they can use Instant.

As the maintainer of Instant, you do not want people to be able to misuse your 
API, if you declare Instant as a B3, then they will see the tearing, so you 
will declare it as a B2 so the whole point of having B3 being a ref by default 
is moot. 

Optional is special not only because null make no sense but also because it's 
size is small enough to be loaded/stored in one (micro-)instruction. 

Rémi 

Reply via email to