Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@archie
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archie/9784771 to your computer and use it in GitHub Desktop.
Save archie/9784771 to your computer and use it in GitHub Desktop.
Exploring wildcard types, or the so called question mark type, in Java.
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