What is the difference between <? super T> and <? extends T> in Java generics?
Greetings, colleagues! I started learning Java generics and encountered wildcards. I read the documentation and watched videos, but I'm still confused about two constructs: ` super T>` and ` extends T>`.
I understand that `? extends T` means "some type that is a subtype of T", and `? super T` means "some type that is a supertype of T". But in practice, I keep getting compilation errors.
For example, I have this code with List:
```java
public class Test {
public static void addNumbers(List super Integer> list) {
list.add(42); // This works
}
public static void readNumbers(List extends Integer> list) {
Integer num = list.get(0); // This works
list.add(42); // Compilation error! Why?
}
}
```