Last active
August 29, 2015 13:57
-
-
Save archie/9784771 to your computer and use it in GitHub Desktop.
Exploring wildcard types, or the so called question mark type, in Java.
This file contains 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
package wild; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
public class Viewer { | |
public void process1(List<Object> items) { | |
for (Object i : items) | |
i.toString(); | |
} | |
public void process2(List<Item> items) { | |
for (Item i : items) | |
i.process(); | |
} | |
public void process3(List<?> items) { | |
for (Object i : items) | |
i.toString(); | |
} | |
public void process4(List<? extends Item> items) { | |
for (Item i : items) | |
i.process(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment