我的代码完全可以工作,但我仍然得到错误"无法从对象转换为char",我想知道是否有人可以向我解释问题是什么,以及我是否可以以另一种方式做到一个错误.
这是导致错误的代码char op = (char) term;.它是从中缀到后缀转换器
//Take terms off the queue in proper order and evaluate
private double evaluatePostfix(DSAQueue<Object> postfixQueue) {
DSAStack<Double> operands = new DSAStack<Double>();
Object term;
//While still terms on queue, take term off.
while(!postfixQueue.isEmpty()) {
term = postfixQueue.dequeue();
if(term instanceof Double) { //If term is double put on stack
operands.push((Double) term);
}
else if(term instanceof Character) { //If term is character, solve
double op1 = operands.pop();
double op2 = operands.pop();
char op = (char) term; …Run Code Online (Sandbox Code Playgroud)