Returning Collection<? extends Type> vs Collection<Type>
What is the difference between these two methods? Collection<Type> getTypes(); vs Collection<? extends Type> getTypes(); Does it matter if Type is a class or an interface? Especially, when designing an API, which version would be preferred and why? Collection<Type> getTypes(); Here, getTypes() must return a Collection<Type> (e.g. ArrayList<Type> or HashSet<Type> ). Collection<? extends Type> getTypes(); Here, getTypes() can return a Collection of anything that is or extends Type , (e.g. ArrayList<SubType> or HashSet<SubType> ). So anything that can be returned from the first variant can also