所以我正在开发一个程序,它将以字符串形式读取数学方程式EG:1 + 2 * 3
我需要有两个不同的堆栈,一个用于操作数的其他堆栈。将数字推入数字堆栈并将操作符推入字符堆栈,然后在满足某些条件时处理等式。我们正在使用已导入环境的ArrayStack。但是,在尝试编译堆栈时,我一直收到错误。
这就是我所拥有的:
public static String test = new String("2 * 3 + 6 ");
public static ArrayStack<Double> numbers = new ArrayStack<Double>[20];
public static ArrayStack<Character> operands = new ArrayStack<Character>[20];
它一直给我这个错误(Ran with -Xlint):
infixNotation.java:7: error: generic array creation
public static ArrayStack<Double> numbers = new ArrayStack<Double>[20];
^
infixNotation.java:8: error: generic array creation
public static ArrayStack<Character> operands = new ArrayStack<Character>[20];
^
/home/tyler/CSC223/bookFiles/ch03/stacks/ArrayStack.java:22: warning: [unchecked] unchecked cast
stack = (T[]) new Object[DEFCAP];
^
required: T[]
found: Object[]
where T is a type-variable:
T extends Object declared in class ArrayStack
/home/tyler/CSC223/bookFiles/ch03/stacks/ArrayStack.java:27: warning: [unchecked] unchecked cast
stack = (T[]) new Object[maxSize];
^
required: T[]
found: Object[]
where T is a type-variable:
T extends Object declared in class ArrayStack
/home/tyler/CSC223/bookFiles/ch03/stacks/StackOverflowException.java:3: warning: [serial] serializable class StackOverflowException has no definition of serialVersionUID
public class StackOverflowException extends RuntimeException
^
2 errors
3 warnings
答案 0 :(得分:3)
public static ArrayStack<Double> numbers = new ArrayStack<Double>[20];
[20]表示你正在制作一个包含20个ArrayStack的数组。但这显然是无稽之谈,因为你甚至没有将该字段声明为数组(除其他外)。
你可能打算用20来调用它的构造函数,所以(20)
public static ArrayStack<Double> numbers = new ArrayStack<Double>(20);