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
}
}
My query is:
If
c1 = (str1, str2) -> 0
and c2 = (str1, str2) -> 1
,
Then why
c1.thenComparing(c2)
is working fine and
((str1, str2) -> 0).thenComparing((str1, str2) -> 1)
is not?