Reputation: 10395
What's difference between these?
public <T extends MyClass> void myMethod (ArrayList<T> list) {
}
public void myMethod (ArrayList<? extends MyClass> list) {
}
Upvotes: 1
Views: 84
Reputation: 62864
<T extends MyClass>
MyClass
, called T
. T
within the method implementation. For example, you can assign elements from the list to new variables of type T
.<? extends MyClass>
MyClass
. The exact substitute is unknown at compile-time and thus, cannot be referred, nor new variables of this very type can be introduced.MyClass
. Additional down-casting may be needed for some specific sub-types of MyClass
.Upvotes: 3
Reputation: 533500
In the first case, you can refer to T
as being the type of the MyClass or sub-class.
In the second case T
can be what ever you have defined outside this method (or nothing if you don't have a type called T)
Upvotes: 2