In this code I have an error on the second line while the first one successfully compiles:
Comparator<? super Integer> a = (x, y) -> Integer.compare(x, y);
Comparator<? super Integer> b = a.thenComparing((x, y) -> Integer.compare(x, y));
The error is "incompatible types: Object cannot be converted to int"
thenComparing
has following signature: thenComparing(Comparator<? super T> other)
,
so as I understand other
in this context will become something like
Comparator<? super super T>
or Comparator<? super super Integer>
.
Why in my example it becomes Comparator<Object>
?
Is this a compiler flaw or is it guarding me from something?