What is the difference between these 2 functions?
static void gPrint(List extends Number> l) {
for (Number n : l) {
System.out.println(n)
The difference is you can't refer to T when using a wildcard.
You aren't right now, so there is "no difference", but here's how you could use T to make a difference:
static T getElement(List l) {
for (T t : l) {
if (some condition)
return t;
}
return null;
}
This will return the same type as whatever is passed in. eg these will both compile:
Integer x = getElement(integerList);
Float y = getElement(floatList);