RFR: 8356995: Provide default methods min(T, T) and max(T, T) in Comparator interface [v7]
Tagir F. Valeev
tvaleev at openjdk.org
Fri Sep 19 07:19:21 UTC 2025
On Thu, 7 Aug 2025 21:05:13 GMT, Stuart Marks <smarks at openjdk.org> wrote:
>> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Add @implSpec
>
> Intuitively, it feels to me like the invariant `min(a, b) == max(b, a)` would be useful when `a` and `b` compare equal. Still mulling this over....
>
> EDIT: never mind. I can't think of a good reason to change the return-first-if-equal rule currently expressed in the spec.
@stuart-marks thank you for the review!
@liach I don't think it's an issue. Yes, it's possible to do the following:
void test(Comparator<Object> cmp) {
String a = "abc";
StringBuilder b = new StringBuilder("abc");
CharSequence max = cmp.max(a, b); // T = Object, U = CharSequence
}
However, saying that "`CharSequence` is the type of `a` and `b`" is not incorrect. If we have an object of type `String`, it's also an object of type `CharSequence`.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25297#issuecomment-3310950943
More information about the core-libs-dev
mailing list