Created
December 27, 2013 08:30
-
-
Save demoth/8144174 to your computer and use it in GitHub Desktop.
PECS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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