问题
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);
}
}
回答1:
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<> ();
回答2:
Or you can import java.util.Stack with the other imports to avoid such type of error.
来源:https://stackoverflow.com/questions/29551507/the-type-stack-is-not-generic-it-cannot-be-parameterized-with-arguments-charac