<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4"><font face="monospace">To answer your question, we
        have to go back to "what were we trying to accomplish with
        records in the first place."  The obvious-but-wrong answer is
        "to free Java developers of the tyranny of boilerplate."  That's
        an important benefit, but that's a consequence, not the main
        goal, of the records design.  <br>
        <br>
        Another way to say this is that records are not just about "make
        me the implementation of the data-carrying class that I want";
        they are not an "implementation generator" like Lombok or Joda
        Beans or Immutables or AutoValue.  Yes, they do some
        implementation lifting, but they also make promises to clients
        as well.  <br>
        <br>
        The list of components in the record header -- the state
        description -- is used to imply a contract: <br>
         - the class has a constructor whose argument list matches
        exactly the state description<br>
         - the class has a deconstruction pattern whose binding list
        matches exactly the state description<br>
         - the class has accessors for every component in the state
        description<br>
         - the class has an equals/hashCode/toString derived from the
        state description<br>
         - the class adheres to a contract that couples the constructor,
        accessors, and equals method, which says that if you take apart
        a record with the accessors, and feed the results back to the
        constructor, you get back an equivalent (according to equals)
        record.  <br>
        <br>
        All of these are derived from the state description, and can be
        counted on by clients.  That is why the state description is
        part of the record declaration, not just implied by the fields. 
        (It is also what lets us derive a stronger serialization
        protocol for records, and in the future, `with` expressions.)  <br>
        <br>
        This is an example of "get the semantics right and the syntax
        takes care of itself."  Records have semantics that permits us
        to boil away the syntax, not the other way around.  <br>
        <br>
        If that's not enough, here's a less philosophical answer why
        your approach would be dangerous.  If you could declare<br>
        <br>
            record R { <br>
                String r;<br>
                int x;<br>
            }<br>
        <br>
        then the implied constructor would take a String and an int. 
        But we are used to being able to freely reorder field and method
        declarations; this has always been a source-, binary-, and
        behavior-compatible change.  But in your model, reordering
        fields would reorder the parameters of the constructor, breaking
        clients (sometimes silently, if you have a record whose fields
        are all the same type.)  <br>
      </font></font><br>
    <div class="moz-cite-prefix">On 11/22/2022 4:25 PM, Heinzl, Steffen
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:6ed0857baed14b68944f6a9598234480@itsc-s164mp.fhws.de">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}div.WordSection1
        {page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi!<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><span lang="EN-US">I wanted to suggest (if
            not yet done) to another syntax to Java records.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I don’t quite understand
            the idea behind the syntax except that some other
            programming languages do it similar.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">A Java class looks like
            this:<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">public class MyClass<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  String s;<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  void myMethod(String
            a, int b);<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">An interface looks like
            this:<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">public interface
            MyInterface<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  void myMethod(String
            c, String d);<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Why all of a sudden is
            it a good idea to change that syntax to:<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">public record
            MyRecord(String r, int x)<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">instead of the following
            syntax (which is also possible in C# by the way)<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">public record MyRecord<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">{<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  String r;<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  int x;<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">}<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I’m teaching Java and I
            find it strange from a lecturer’s point of view to explain
            the rationale for introducing the syntax like that. I’d be
            glad if someone could enlighten me!<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span style="color:#1F497D;mso-fareast-language:DE" lang="EN-US">Thanks!
            Best,<o:p></o:p></span></p>
        <p class="MsoNormal"><span style="color:#1F497D;mso-fareast-language:DE" lang="EN-US">Steffen</span><span style="font-size:9.0pt;color:#1F497D;mso-fareast-language:DE" lang="EN-US"><o:p></o:p></span></p>
        <p class="MsoNormal"><span style="font-size:9.0pt;color:black;mso-fareast-language:DE" lang="EN-US"><o:p> </o:p></span></p>
      </div>
    </blockquote>
    <br>
  </body>
</html>