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

梦想的初衷 提交于 2019-12-02 22:41:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!