0
私はこのような方法を持っています。今メソッド参照がこれで動作しないのはなぜですか?
static <R> R applyOthers(Some some, Function<List<Other>, R> function) {
List<Other> others = ...;
return function.appply(others);
}
私はこれを試してみてください、
withSome(some -> {
List<Other> others1 = applyOthers(some, v -> v); // works
List<Other> others2 = applyOthers(some, Function::identity); // doesn't
});
エラー、私が得ます。
incompatible types: unexpected static method <T>identity() found in unbound lookup
where T is a type variable:
T extends Object declared in method <T>identity()
なぜ::identity
が機能しないのですか?
これは、メイトです! 'Function :: identity'ではなく、' Function.identity() 'でなければなりません。ありがとう。 –