Search code examples
javagenericscollectionsstack

The type Stack is not generic; it cannot be parameterized with arguments <Character>


I am trying to write a simple program to use stacks.It is giving me the error

The type Stack is not generic; it cannot be parameterized with arguments

import java.util.*;

    public class Stack {
            public static void main(String[] args)
            {
                Stack<Character> stack = new Stack<> ();
                s.push("Hello");
                System.out.println(s);

            }

        }

Solution

  • Your class Stack is shadowing java.util.Stack. You could rename your class, or use the fully qualified class name like

    java.util.Stack<Character> stack = new java.util.Stack<> ();