Skip to content

Instantly share code, notes, and snippets.

@demoth
Created December 27, 2013 08:30
Show Gist options
  • Save demoth/8144174 to your computer and use it in GitHub Desktop.
Save demoth/8144174 to your computer and use it in GitHub Desktop.
PECS
class A{}
class B extends A{}
class C extends B{}
public class MainGenerics {
public static void main(String[] args) {
List<? extends B> producer = new ArrayList<C>();
for (B b : producer){}
for (A a : producer){}
List<? super B> consumer = new ArrayList<A>();
consumer.add(new B());
consumer.add(new C());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment