Can someone please explain why inlining evensFirst
causes compilation to fail?
import java.util.Comparator;
public class Main
{
public static void main(String[] args) {
Comparator<Integer> evensFirst = Comparator.comparingInt(t -> t%2);
Comparator<Integer> oddsFirst = evensFirst.reversed();
// Inlining evensFirst causes compilation to fail with
// "The operator % is undefined for the argument type(s) Object, int"
Comparator<Integer> oddsFirst2 = Comparator.comparingInt(t -> t%2).reversed();
}
}
- I assume it's something related to generics and type inference, but what is the explanation?
- And how can I have the code inline?