I created a Java class to decorate another interface with generics. However, it always has some compiler errors. This is the tailored sample code that could reproduce the error.
public interface GenericInterface<T> {
<U, V> GenericInterface<V> testFunc(BiFunction<? super T, ? super U, ? extends V> biFunction);
}
class GenericClass<T> implements GenericInterface<T> {
private GenericInterface<T> delegate;
public GenericClass(GenericInterface<T> dele) {
this.delegate = dele;
}
@Override
public <U, V> GenericInterface<V> testFunc(BiFunction<? super T, ? super U, ? extends V> biFunction) {
GenericClass<T> impl = new GenericClass<T>(delegate);
return impl.testFunc((t, u) -> {
// Do something here ...
// ...
// Error for argument u: Required type: capture of ? super U, Provided: Object
return biFunction.apply(t, u);
});
}
}
I tried a whole week and could not figure out what's wrong with it. Actually, I am new to advanced Java generics.