Samplasion
Samplasion

Reputation: 527

Getting a Class Type to be a specific class

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

Answers (1)

M. le Rutte
M. le Rutte

Reputation: 3563

Use

public class IntArrayList extends NewArrayList<Integer> 

this binds the < T > and removes it for further subclasses.

Upvotes: 6

Related Questions