Hi Manoj,

In the current implementation methods `equals` and `hashCode` are final regardless of the corresponding record being explicitly of implicitly final. The fact that `toString` is not final is just a lack of consistency that should be fixed but we should probably decide what the spec should say about this first and then do the same for all the implicitly generated methods.

In the case of `strictfp` the spec says in section `8.1.1.3 strictfp Classes`:

....
This implies that all methods declared in the class, and all nested types declared in
the class, are implicitly strictfp .
....

so this is not related to records, as every class with the `strictfp` modifier applied will propagate it down to all its members.

Thanks,
Vicente

On 2/21/20 1:24 AM, Manoj Palat wrote:
Hi,
 (a) Given a record,  recordR(inta){}, I see the (implicit) final modifiers propagated to implicit methods hashCode() and equals()
[javap output]

public *final* boolean equals(java.lang.Object);

 However, toString() does not get the same ->

public java.lang.String toString();

(b)  Adding an explicit modifier, say strictfp adds this to all three

*strictfp**record*R(*int*a){}

public strictfp java.lang.String toString();

public final strictfp int hashCode();

public final strictfp boolean equals(java.lang.Object);

I didn't see this explicitly specified in the Records JLS -> http://cr.openjdk.java.net/~gbierman/jep359/jep359-20200115/specs/records-jls.html#jls-8.10.3
Spec needs change? Or is there a newer version of spec ?
Regards,
Manoj


Reply via email to