RFR: 8356995: Provide default methods min(T, T) and max(T, T) in Comparator interface [v7]

Stuart Marks smarks at openjdk.org
Fri Sep 19 02:28:57 UTC 2025


On Thu, 18 Sep 2025 22:34:52 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add @implSpec
>
> src/java.base/share/classes/java/util/Comparator.java line 201:
> 
>> 199:      * @param   o1   an argument.
>> 200:      * @param   o2   another argument.
>> 201:      * @param   <U> the type of the arguments and the result.
> 
> Since we are utilizing the least upper bound here, we can probably describe this as:
> 
> "captures the least upper bound of argument types for the result type"
> 
> Or should we leave an API note?

Most docs for type arguments aren't that specific. I checked a bunch in Collections, Collection, and Class, and they're pretty simple and not precise. For example, in Collection we have:

    <T> T[] toArray(T[] a)

    @param <T> the component type of the array to contain the collection

Additionally, I'm not sure that `U` is actually the LUB of the types of the arguments. `U`'s upper bound of `T` might require it to be something different.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25297#discussion_r2361554171


More information about the core-libs-dev mailing list