----- Original Message ----- > From: "John Rose" <john.r.r...@oracle.com> > To: "daniel smith" <daniel.sm...@oracle.com> > Cc: "Remi Forax" <fo...@univ-mlv.fr>, "valhalla-spec-experts" > <valhalla-spec-experts@openjdk.java.net> > Sent: Thursday, January 6, 2022 4:53:28 AM > Subject: Re: Updated State of Valhalla documents
>> On Jan 5, 2022, at 4:45 PM, Dan Smith <daniel.sm...@oracle.com> wrote: >> >> Not talking about the VM. I'm talking about the language model. >> >>> A primitive (B3) does not provide proper encapsulation unlike a classical >>> Java >>> class (the one spelt "class" in the language), >> >> You should say "object" here, not "class". Primitive values have classes, >> even >> though they are not objects. > > Yes. And what’s more, Remi’s point about encapsulation is weak, because we can > (possibly) assume that every author of a primitive class has checked those > boxes off, saying that all-zero default is a valid value and tearing is > acceptable. There are plenty of Java B1 classes today that are designed with > such weaknesses. Class abstractions come in various strengths as selected by > each class’s author. Selecting primitive for a class forces the author to > gives > up some abstraction but keeps most abstraction decisions intact. Being a primitive weaken the encapsulation, but your are right that it's not a all or nothing thing. > > Having the required hardwired null-arg constructor syntactically present is an > interesting idea to ensure that the author has explicitly “checked the box” > about the default value. Not sure it’s worth it though. If we want to check the other box, tearing, at least partially, i suppose that creating a VarHandle on a non volatile primitive class should be rejected too. Rémi