Im trying to compile this code, but I keep getting a compile error: '(' or ' What am I doing wrong? Thanks in advance


public class Postfix {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<Integer>(); ------> HERE

        while (!StdIn.isEmpty()) {
            String s = StdIn.readString();
            if      (s.equals("+")) stack.push(stack.pop() + stack.pop());
            else if (s.equals("*")) stack.push(stack.pop() * stack.pop());
            else stack.push(Integer.parseInt(s));
        }
        System.out.println(stack.pop());
    }
}

Are you compiling against JDK 1.5 or 1.6? Generics were introduced in 1.5 and if your JDK is older it won't like that declaration.

yeah my bad, I was compiling with 1.4.3, I just upgrade Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.