There was a strange problem in my project. Now I have simplified the problem and written a small example here to illustrate my confusion:
public class Question { class Q1 {} class Q2 extends Q1 {} interface In<T> { void f(T t); } List<Q2> list; void f(In<? super List<? super Q2>> in) { in.f(list); } static void g() { Question question = new Question(); In<Collection<Q1>> in1 = new In<Collection<Q1>>() { @Override public void f(Collection<Q1> o) {} }; In<List<Q2>> in2 = new In<List<Q2>>() { @Override public void f(List<Q2> o) {} }; question.f(in1);
My goal is to make the f(In<? super List<? super Q2>>) method more flexible. I can pass in1 or in2 method. But not one of them can be transmitted! What's wrong?
Perhaps this answer will make sense. But my question is different! My common type is In<? super List<? super Q2>> In<? super List<? super Q2>> In<? super List<? super Q2>> , a generic type in a generic type.
source share