Can somebody explain me what the difference is between these two methods? Are they same? They do look same to me in terms of what they solve. If they are same, why need ?
?
Method #1, Unbounded
public static void printList(List<?> list) {
for (Object elem : list)
System.out.println(elem + " ");
System.out.println();
}
Method #2, Unbounded:
public static <T> void printList(List<T> list) {
for (Object elem : list)
System.out.println(elem + " ");
System.out.println();
}
Method #1, Bounded
public static void printList(List<? extends Number> list) {
for (Object elem : list)
System.out.println(elem + " ");
System.out.println();
}
Method #2, Bounded:
public static <T extends Number> void printList(List<T> list) {
for (Object elem : list)
System.out.println(elem + " ");
System.out.println();
}