There is such code:
interface SomeFunc<T> { T func(T t); } public class LambdaDemo { public static void main(String[] args) { SomeFunc<String> reverse = (str) -> { String result = ""; for (int i = str.length()-1; i >= 0; i--) { result += str.charAt(i); } return result; }; Rever foo = new Rever(); foo.doSmth(reverse, "reverse"); } } class Rever { public void doSmth(SomeFunc<?> func, String n) { System.out.println(func.func(n)); } } But the compiler produces the following error:
[Java] The method of
func(capture#1-of ?)In the typeSomeFunc<capture#1-of ?>
What is my mistake and how to fix it?
SomeFuncinterface is superfluous, since for this purpose the standard library hasUnaryOperator<T>, which is the successor ofFunction<T, T>- iksuy