I understand upper bound clearly, but don't fully understand lower bound. As for example I have this code:
public class Main<T> {
private T t;
public Main(T t) {
this.t = t;
}
private static class Base {}
public static void main(String[] args) {
Main<? super Base> main = new Main<>(new StringBuilder());
System.out.println(main.t.getClass());
}
}
Why there is no error during compile despite of StringBuilder
isn't super class of Base
. As I thought it would be illegal to provide type which is irrelevant (I know that it's impossible to assign non child class to t
after type inference). Also it works with collections, does it means that collection could possibly store no child, no super class of Base
? Please do not link me to PECS questions, I have read them a lot.