Skip to content

Instantly share code, notes, and snippets.

@darrenbkl
Created January 22, 2020 11:31
Show Gist options
  • Save darrenbkl/1e77a7ebf06314b7070054c94467d433 to your computer and use it in GitHub Desktop.
Save darrenbkl/1e77a7ebf06314b7070054c94467d433 to your computer and use it in GitHub Desktop.
public static void printList(List<? extends Number> numList) {
for (Number n : numList) {
System.out.println(n);
}
}
List<Integer> integerList = new ArrayList<>(Arrays.asList(1, 2, 3));
List<Double> doubleList = new ArrayList<>(Arrays.asList(1.1, 2.2, 3.3));
printList(integerList); // 1, 2, 3
printList(doubleList); // 1.1, 2.2, 3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment