Reputation: 527
I have a class like
public class NewArrayList<T> extends ArrayList {
// ...
}
And another class:
public class IntArrayList<T> extends NewArrayList<T> {
/* something like throwing an exception if T is not Integer */
// Integer-only methods
}
IntArrayList<T>
is supposed to only accept Integer
values. I have tried T instanceof Integer
but it only errors. How can I achieve that?
Upvotes: 0
Views: 60
Reputation: 3563
Use
public class IntArrayList extends NewArrayList<Integer>
this binds the < T > and removes it for further subclasses.
Upvotes: 6