Why there is <?e extends T>
instead of <T>
in unmodifiable APIs of java.util.Collections
e.g. consider unmodifiableLis API
public static <T> List<T> unmodifiableList(List<? extends T> list)
Why not, just
public static <T> List<T> unmodifiableList(List<T> list)
Edit:
This is not duplicate of When do Java generics require instead of and is there any downside of switching. That question intend to find the importance of <? extends T>
over <T>
and what would be the impact if change is done from one to other. I understand the difference in both syntax (<? extends T>
and <T>
), however in case of unmodifiable collection APIs, context (and hence my question) is different.