Oh, and PLEASE, PEOPLE:

Do not just reply to a message with a topic like "draft spec for records", unless your mail consists 100% exclusively of actionable comments on the draft spec.  If you have a question, or a design comment, MAKE A NEW THREAD.  Please.

On 9/5/2019 5:45 PM, fo...@univ-mlv.fr wrote:

----- Mail original -----
De: "Brian Goetz" <brian.go...@oracle.com>
À: "Remi Forax" <fo...@univ-mlv.fr>
Cc: "John Rose" <john.r.r...@oracle.com>, "amber-spec-experts" 
<amber-spec-experts@openjdk.java.net>
Envoyé: Jeudi 5 Septembre 2019 22:55:13
Objet: Re: Draft JLS spec for records
We are circulating back to my first question, why the constructor has
to be public.

Think about it some more.  Suppose the default was that the constructor
was private.  Now, without specifying a constructor, no record could be
instantiated at all, without the user declaring a constructor!  That
would be terrible.  Part of the point here is that the require acquires
a standard, sensible external API _without_ the user having to declare
these elements.  Users's get to say `record Foo(String s)`, and get
everything they need to use the record.

If Java had factories, then we could quite sensibly decide the mandated
API is a private ctor and a public factory.  But it doesn't, so we can't.

OK, I suppose the next thing you are going to say is "Sigh, I guess the
default (implicit) constructor has to be public, but if I _explicitly_
provide a constructor, I should be able to 'remove' it from the API."
It's not what i'm saying.

[...]

In fact, one by one, we've been
_removing_ gratuitous differences between records and classes, and each
time we did, the design seems to have gotten better.
I fully agree, you should have exactly the same rules as with the classes,
so the canonical constructor should follow the same rule as the default 
constructor.

Also why having the constructor public helps to make the record instantiatable, 
a constructor to be accessible by reflection requires that both the class and 
the constructor to be public. So following your point, does it means that all 
record have to be public too ?

Rémi

Reply via email to