Search code examples
javageneric-collections

Why Stack in java cannot be created with type parameter(generic)


Stack is a generic class in Java, it definition is class Stack<E> extends Vector<E>, but why I cannot instantiate it with type parameter like Stack<Integer> s = new Stack<>(); But a Vector can?


Solution

  • Of course, it can.

        Stack<Integer> stack = new Stack<>();