In java8 when I try to write this code
List<? extends String> list = new ArrayList<>();
list.add("a");
I get an error
Required type: capture of ? extends String - Provided: String
When I try this code
List<String> stings1 = new ArrayList<>();
List<String> stings2 = new ArrayList<>();
stings1.addAll(stings2);
It works fine, however, the signature of addAll method is boolean addAll(Collection<? extends E> c);
and it shouldn't accept the same type it extends like the previous example.
I'm curious if ? extends T
should accept T or not!!