[records] updates for Preview 9. hashCode

Remi Forax forax at univ-mlv.fr
Tue Jan 14 23:00:44 UTC 2020

> De: "John Rose" <john.r.rose at oracle.com>
> À: "Daniel Heidinga" <Daniel_Heidinga at ca.ibm.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 14 Janvier 2020 23:49:54
> Objet: Re: [records] updates for Preview 9. hashCode

> On Jan 14, 2020, at 6:49 AM, Daniel Heidinga < [
> mailto:Daniel_Heidinga at ca.ibm.com | Daniel_Heidinga at ca.ibm.com ] > wrote:

>> This gets a +1 from me. The format is clear - explained so it's easy
>> to understand what the parts mean - and explicit that it may change.

>> We can't ever stop users from parsing #toString but this is explicit
>> that's a bad idea for them to do so.

> OK, so I’ve updated the proposed doc change along those lines.

> [ http://cr.openjdk.java.net/~jrose/draft/record-contract |
> http://cr.openjdk.java.net/~jrose/draft/record-contract ]

> (Previous versions are …/record-contract.{00,01}.)

> I adapted the javadoc from AbstractMap::toString, and
> then added some sample code, just for grins. It would be
> fine to delete the sample code.

> * @implNote
> * The implicitly provided implementation returns a string which begins
> * with the unqualified name of the record class and is immediately
> * followed by a list of components, in declaration order,
> * enclosed in square brackets ({@code "[]"}). Adjacent components
> * are separated by the characters {@code ", "} (comma and space).
> * Each component is rendered as the name followed by an equals sign
> * ({@code "="}) followed by a string representing the associated value.

> The language is intentionally vague about what is “a string representing
> the associated value”. There are comments in the prototype that mention
> maybe adding quotes to some values (Strings). So I left that open.

This is almost OT but it's a question I was asked for twice, 
what is the rational to use the angle bracket instead of the parenthesis ? 
Using parenthesis makes the syntax and the returns of toString() more close together, the one mirroring the other. 

My answer is that a record is a named tuple, so the closest approximation we have is a list of entries (Map.Entry) hence the syntax. 

> — John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200115/c4a20286/attachment.htm>

More information about the amber-spec-experts mailing list