“PECS” in Java — Easy visualization

PECS — “Producer Extends, Consumer Super”
<? super SomeType>
<? extends SomeType>

You CAN’T put a bigger box into a smaller one.

Our cute cat can be big enough if her box is big :)
public class Collections { 
public static <T> void copy(List<? super T> dest, List<? extends T> src) {
for (int i = 0; i < src.size(); i++)
dest.set(i, src.get(i));
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store