RFR: 8199318: add idempotent copy operation for Map.Entry
John Rose
john.r.rose at oracle.com
Thu Jun 3 20:51:28 UTC 2021
On Jun 3, 2021, at 12:46 PM, Remi Forax <forax at univ-mlv.fr<mailto:forax at univ-mlv.fr>> 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
— John
More information about the core-libs-dev
mailing list