Finding max or min of exactly two objects

Peter Levart peter.levart at gmail.com
Wed May 14 21:07:16 UTC 2025


Hi,

I don't know if anyone still uses this, but some ideas are worth 
considering:

https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/Ordering.java

This is a Comparator implementation that also defines min and max. As 
generic methods.


So if I have:

Comparator<CharSequence> cmp = ...

var greatest = cmp.max("foo", "bar");

...what type will greatest be?

Regards, Peter

On 5/14/25 10:15 PM, Tagir Valeev wrote:

> Hello!
>
> On Tue, May 13, 2025 at 5:53 PM Brian Goetz <brian.goetz at oracle.com> wrote:
>> Let's separate these.  I think the first two have a good claim to be in
>> Comparator; I think the latter two probably live better in Comparable,
>> which feels like a separate conversation (and maybe less important?)
>> (And also, there's some overlap with some yet-uncollapsed stuff going on
>> in Valhalla that I'd like to steer clear of.)
> Agreed, let's concentrate on default methods first and see how it
> goes. I've created
> https://bugs.openjdk.org/browse/JDK-8356995
> I've also found an older (declined) feature request
> https://bugs.openjdk.org/browse/JDK-4254492
>
> With best regards,
> Tagir Valeev


More information about the core-libs-dev mailing list