See

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Objects.html#compare(T,T,java.util.Comparator)

-Joe

On 1/6/2019 2:56 AM, Zheka Kozlov wrote:
Why don't we just add a generic method which compares any instances of
Comparable?

public interface Comparator<T> {
         ...

public static <T extends Comparable<? super T>> boolean equal(T x, T y) {
return x.compareTo(y) == 0;
}
}

Usage:

Comparator.equal(1, 1); // true
Comparator.equal(1.0, 1.0); // true
Comparator.equal(2.0f, 2.0f); // true
Comparator.equal("abc", "def"); // false
Comparator.equal("abc", 1); // compilation error

сб, 5 янв. 2019 г. в 09:33, <
some-java-user-99206970363698485...@vodafonemail.de>:

Hello Remi,
You are right, the proposed method names would prevent backwards
compatibility, I forgot to think
about that. Sorry for the trouble.
Maybe a different, currently not used name, such as `areEqual`,
`primitiveEquals` or similar would
be better.
What do You think about the addition of such a method?

Kind regards

Remi Forax <fo...@univ-mlv.fr> hat am 5. Januar 2019 um 00:50
geschrieben:

Hi,
it's not obvious to me that this is a source backward compatible change.

if you have something like:
   interface Fun { boolean eq(Double a, double b); }
   ...
   Fun fun = Double::equals;

it's not clear to me which variant will be selected ?

regards,
Rémi

Reply via email to