I\'m just learning about generics in Java from a textbook, where it talks about a class GenericStack
implemented with an ArrayList
There are two parts to this:
The generic type parameter given for the class definition is available within the class itself.
You can have generic types specific to individual methods (including constructor).
Look at the following example:
package snippet;
import java.util.ArrayList;
public class Y extends ArrayList {
public Y(T t) {
}
}
Where as the type E
is available to the whole of the class, the type T
is valid only within the constructor.