Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why <? extends interface> instead of <? implements interface> [closed]

I have the following code:

ArrayList<? extends IValues> valuesList

IValues is an interface. The list is filled with classes/objects that implement the IValues interface. I do understand the the concept of every object in this list having to fulfill the contract laid down by the interface they implement. Why doesn't the java language do this like this:

ArrayList<? implements IValues> valuesList

? This would be much clearer to the user, wouldn't it?

like image 602
fweigl Avatar asked May 06 '26 20:05

fweigl


1 Answers

That's how Generics are designed in Java.

Note that the super keyword is used here, as well, but it has totally different meaning than outside Generics.

like image 124
Konstantin Yovkov Avatar answered May 09 '26 09:05

Konstantin Yovkov