Updated State of Valhalla documents

forax at univ-mlv.fr forax at univ-mlv.fr
Thu Jan 6 00:14:36 UTC 2022


----- Original Message -----
> From: "daniel smith" <daniel.smith at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>
> Sent: Thursday, January 6, 2022 12:37:09 AM
> Subject: Re: Updated State of Valhalla documents

>> On Dec 23, 2021, at 12:58 PM, forax at univ-mlv.fr wrote:
>> 
>> But for Java, i would argue that the model is more
>> we have either reference objects or primitives, for reference objects you have
>> those with identity and those without identity,
>> hence "primitive" being a top-level kind while "value" (or a better term) being
>> a modifier.
> 
> I don't want to get too in the weeds on syntax (even though, yes, it does help
> convey the underlying model!). The change you propose is, indeed, a possibility
> that is still on the table.
> 
> But: it's really important to understand that, in the proposed model, primitive
> values, identity objects, and value objects *all* belong to classes. That's
> where they get their members, via the normal rules about class membership. A
> primitive value is an instance of a class, even though it is not an object.
> 
> Whether we use the syntax 'c l a s s' in the primitive declaration, the thing
> being declared is a class. Just like the thing being declared with 'e n u m' is
> a class.

yes,
for the VM, a lambda, a record or an enum are all classes, even if in the syntax the keyword "class" is not used.

A primitive (B3) does not provide proper encapsulation unlike a classical Java class (the one spelt "class" in the language),
because
- the default value (the fields fill with zeroes) is always a valid value
- a primitive is tearable

I'm trying to find ways to convey that semantics through the syntax, because most users, at least at the beginning, derive the semantics from the syntax,
- Not using "primitive class" but only "primitive" is a possible step.
- Forcing to have a default constructor automatically generated with the same visiblity as the class that can not be overridden (apart to add javadoc) by the user is another possible step. 

As another example, Anderson Vasconcelos Pires proposed on the dev mailing list to not use "new" to create a primitive object, i believe because a primitive object does not require a heap allocation, so it may make sense to not use "new" the same way we do not use "new" in front of a lambda. But it's a counter example, because we know that if primitive can be created without new people will abuse of it and declare primitive classes where they should not, just to avoid 3 keystrokes.

regards,
Rémi


More information about the valhalla-spec-observers mailing list