I am trying to understand, why compiler rejects / accepts the following arguments.
I assumed, that both arguments would be accepted, because both Sets contain nothing, but children of Serializable.
And being a child of Serializable - is the only thing, which is enforced by method signature D extends Serializable - right?
Why is the Set serializables1 of type D extends Serializable accepted?
Why is the Set serializables2 of type ? extends Serializable rejected?
Why is D extends Serializable and ? extends Serializable is not the same here?
public class GenTest<D extends Serializable> {
Set<D> serializables1;
Set<? extends Serializable> serializables2;
public static void main(String[] args) {
GenTest<Serializable> g = null;
g.accept(g.serializables1); // OK - WHY?
g.accept(g.serializables2); // NOT OK - WHY?
}
void accept(Set<D> serializables) {}
}