import java.util.*;
class TreeMapDemo
{
public static void main(String args[])
{
Comparator <String> c1 = (str1, str2) -> 0;
Comparator <String> c2 = (str1, str2) -> 1;
TreeMap <String, Double> tm1 = new TreeMap(c1.thenComparing(c2));
//Working fine
TreeMap <String, Double> tm2 = new TreeMap(((str1, str2) -> 0).thenComparing((str1, str2) -> 1));
//Error: Lambda expression not expected here
//<none> can not be dereferenced
}
}
我的查询是:
如果
c1 = (str1, str2) -> 0
和c2 = (str1, str2) -> 1
,
那么为什么
c1.thenComparing(c2)
工作正常并且
((str1, str2) -> 0).thenComparing((str1, str2) -> 1)
不是?