> De: "John Rose" <john. [email protected] > > À: "Remi Forax" < [email protected] > > Cc: "Peter Levart" < [email protected] >, "Rémi Forax" < > [email protected] >, "core-libs-dev" < [email protected] > > Envoyé: Jeudi 3 Juin 2021 22:51:28 > Objet: Re: RFR: 8199318: add idempotent copy operation for Map.Entry
> On Jun 3, 2021, at 12:46 PM, Remi Forax < [ mailto:[email protected] | > [email protected] ] > wrote: >> I kind of regret that the compiler does not provide automatically an >> implementation of compareTo if the record implements Comparable. >> People sucks at writing compareTo and the resulting bugs are hard to >> find/reproduce. > That’s a slippery slope. IIRC we consciously stopped > before that step. > That said, there are other ways to fix this. We should > have utilities (maybe in the JDK but not the JLS) which > build such methods and make it easy for users to grab onto > them. Maybe something like this: > interface ComparableRecord<T extends Record & ComparableRecord<T>> > extends Comparable<T> { … } > record Foo(int x, String y) implements ComparableRecord<Foo> { … } > [ http://cr.openjdk.java.net/~jrose/draft/ComparableRecord.java | > http://cr.openjdk.java.net/~jrose/draft/ComparableRecord.java ] [repost with a link] The main issue with this kind of code is that the JIT does not see through the ClassValue. Tweaking a little bit your code, I get https://gist.github.com/forax/e76367e1a90bf011692ee9bec65ff0f8 (It's a PITA that we have to use a raw type to workaround circularly defined parameter type) > — John Rémi
