Java 8の新機能を紹介します。
私は次のクラスを持っています:
class InstanceMethodClass {
Integer testStr(String str1,String str2) {
return str1.compareTo(str2);
}
}
および次の呼び出し:
Arrays.sort(new String[]{"1", "3","2"},InstanceMethodClass::testStr );
その後、次のエラーが表示されます。
java: no suitable method found for sort(java.lang.String[],InstanceMe[...]stStr)
method java.util.Arrays.<T>sort(T[],java.util.Comparator<? super T>) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; invalid method reference
cannot find symbol
symbol: method testStr(T,T)
location: class lambdas.staticReferences.InstanceMethodClass))
method java.util.Arrays.<T>sort(T[],int,int,java.util.Comparator<? super T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
何が間違っているのか説明してください。