Is there any difference between:
static void findMax(LinkedList extends Number> list){...}
and:
static void findMax(LinkedList list){...}
Since both work, I'd like to know if there's any big difference between the two and which is advised.
解决方案
The main difference is that in the second version you can access the type T whereas in the first one you can't.
For example, you might want to return something linked to T (e.g. returning T instead of void):
static T findMax(LinkedList list){...}
Or you might need to create a new list of Ts:
static void findMax(LinkedList list){
List copyAsArrayList = new ArrayList<> (list);
//do something with the copy
}
If you don't need access to T, both versions are functionally equivalent.