I have the following code snippet, at the first glance it should work, but I receive very interesting error:
'apply(capture<? extends Generic.MyClass>)' in 'java.util.function.Function' cannot be applied to '(capture<? extends Generic.MyClass>)'
This error occurs here: function.apply(wrapper.value);
What am I missing?
public class Generic {
public static void main(String[] args) {
Wrapper wrapper = new Wrapper<>(new MyClass());
}
private static void method(Wrapper<? extends MyClass> wrapper) {
Function<? extends MyClass, String> function = (MyClass m) -> m.getClass().toString();
function.apply(wrapper.value);
}
static class Wrapper<T extends MyClass> {
private final T value;
Wrapper(T value) {
this.value = value;
}
}
static class MyClass {
}
}