Let\'s say I have a Pair class
public class Pair {
public P p;
public Q q;
public Pair(P p, Q q) {
this.p = p;
this
The error seems to be related to Pair's generic parameters. One workaround it to use an explicit type, as you've attempted:
pairList.sort(Comparator.comparingInt(Pair::firstValue).thenComparingInt(Pair::secondValue));
// ^^^^^^
Note the comparingInt() which reduces the number of parameters you need to specify, and improves performance by avoiding boxing.
Another solution is to parameterize the type reference:
pairList.sort(Comparator.comparingInt(Pair,?>::firstValue).thenComparingInt(Pair::secondValue));
// ^^^^^