JLS talks about compiling time to reference the ReferenceType :: [TypeArguments] method. Identifiers can be interpreted in different ways.
For the target function type with n parameters, a set of potentially applicable methods is determined:
ReferenceType :: [TypeArguments] The identifier has two different categories: n and n-1, which take into account the possibility that this form refers to either a static method or an instance method.
Expression for a reference expression of the form ReferenceType :: [TypeArguments] The identifier can be interpreted in different ways. If the Identifier refers to the instance method, then the implicit lambda expression has an additional parameter of type this compared to if the Identifier refers to the static method. Both types of applicable methods can be used for ReferenceType, therefore, the search algorithm described above identifies them separately, since for each case there are different types of parameters.
Comparator.comparing method accept Function <T, R extends Comparable <? →> . when you use String::compareToIgnoreCase , which will report an error because it has two parameters, one implicit this other is a method parameter comparison string , so it looks more like BiFunction<String,String,Integer> not a Function<String,Integer> .
BiFunction<String, String, Integer> comparator = String::compareToIgnoreCase;
Stream.sort method accept Comparator , and Comparator is more like BiFunction<T,T,Integer> , therefore it is compatible with String::compareToIgnoreCase . on the other hand, they can be used interchangeably. eg:
Comparator<String> primary = String::compareToIgnoreCase; BiFunction<String, String, Integer> comparator1 = primary::compare; Comparator<String> comparator2 = comparator1::apply;
you can use comparing(String::toLowerCase) instead, it is equivalent to String::compareToIgnoreCase , for example: