<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Brian Goetz" <brian.goetz@oracle.com><br><b>À: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"John Rose" <john.r.rose@oracle.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Envoyé: </b>Jeudi 5 Septembre 2019 21:24:55<br><b>Objet: </b>Re: Draft JLS spec for records<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><div>[...]<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><br>
<br>
<blockquote cite="mid:668192015.2065330.1567710614128.JavaMail.zimbra@u-pem.fr">
<div style="font-family: arial, helvetica, sans-serif; font-size:
12pt; color: #000000">
<div>
<div>But i don't think it's a good idea to make all records
"serializable" (in the general sense) by default</div>
</div>
</div>
</blockquote>
<br>
No one is suggesting that. Serialization was an example; OR mappers
was another. These are examples of the general principle that "we
want records to be instantiable by frameworks", which means they
need a way to find the constructor reflectively. </blockquote><div><br></div><div>Writing a wrapper class that is able to serialize any records is easy if the constructor is always public.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Here you are moving from "the internal implementation and the external API are the same thing" to "and records are instantiable by frameworks", that's a huge leap.</div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><br>
<br>
<blockquote cite="mid:668192015.2065330.1567710614128.JavaMail.zimbra@u-pem.fr">
<div style="font-family: arial, helvetica, sans-serif; font-size:
12pt; color: #000000">
<div>Java serialization is not the
best mechanism, mostly because of its implementation, but at
least there is one thing right, being serializable is opt-in.<br>
<div>I believe we should follow the same principle by allowing
the constructor to be public or private, you are opting for
being serializable (in the general sense) or not.<br>
</div>
</div>
</div>
</blockquote>
<br>
Among other things, unless we're willing to have _yet a third_
default accessibility (one for classes, one for interfaces, and yet
another for records), then the obvious thing people will type:<br>
<br>
record R(int x) {<br>
R { ... }<br>
}<br>
<br>
would leave the ctor as package-private, which is probably not what
people want either. Nope.</blockquote><div><br></div><div><div>It's exactly what you get with a class.</div></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><br>
<br>
I sympathize with the concern that "public ctor is not the best
thing to expose". Until someone offers something better, though,
this is the best we've got so far. <br>
<br></blockquote><div><br></div><div><div>We are circulating back to my first question, why the constructor has to be public.<br></div><div><br></div><div>I don't understand why we have to make records different from classes on that subject.<br></div><div>If the constructor is public then deserialization libraries can using it, otherwise it can't.<br></div><div><br></div><div>Rémi</div><div><br data-mce-bogus="1"></div></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>