Issue
What is the difference between these 2 functions?
static void gPrint(List<? extends Number> l) {
for (Number n : l) {
System.out.println(n);
}
}
static <T extends Number> void gPrintA(List<T> l) {
for (Number n : l) {
System.out.println(n);
}
}
I see the same output.
Solution
There is no difference in this case, because T
is never used again.
The reason for declaring a T
is so that you can refer to it again, thus binding two parameter types, or a return type together.
Answered By - Thilo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.