Let’s say I have these classes:
class A<T> {
void set(T t) {}
}
class B<T> {
T get() { return null; }
}
class C extends A<String> { }
class D extends B<String> { }
class E extends A<Long> { }
class F extends B<Long> { }
And these variables:
A<?> a1 = new C();
B<?> b1 = new D();
A<?> a2 = new E();
B<?> b2 = new F();
Can I do these somehow (with some magic?):
a1.set(b1.get());
a2.set(b2.get());
No. But you can do
A<?>means A of some class, but I don’t know which one. So you can’t call itsset()method because the compiler doesn’t know if the type of the argument matches with the actual generic type of A.