PECS

A rule of thumb for generic wildcards: a collection that produces values for you uses extends, and one that consumes values from you uses super.

In more detail

PECS stands for producer extends, consumer super. It follows from how the compiler protects collections: you may read from an unknown subtype and write to an unknown parent type. If a method both reads and writes, use an exact type instead of a wildcard.

Related terms

Taught in

References