【发布时间】:2019-04-15 05:34:58
【问题描述】:
我在后缀计算器中遇到此错误:整数操作数无法解析或不是字段。下面我展示了主要代码,以及来自 IntegerOperand 类文件的代码。我怎样才能解决这个问题?我正在尝试从 IntegerOperand 类调用 add 函数。
public class IntegerOperand implements CalculatorOperand<IntegerOperand> {
BigInteger value;
IntegerOperand (BigInteger value) {
this.value = value;
}
public IntegerOperand add (IntegerOperand that) {
return new IntegerOperand(this.value.add(that.value));
}
public IntegerOperand subtract (IntegerOperand that) {
return new IntegerOperand(this.value.subtract(that.value));
}
public IntegerOperand multiply (IntegerOperand that) {
return new IntegerOperand(this.value.multiply(that.value));
}
public String toString () {
return value.toString();
}
}
public void operation (OperationType operation) {
T t1;
T t2;
if(stack.isEmpty())
{
t2= stack.pop();
t1= stack.pop();
stack.push(t1.IntegerOperand.add(t2));
}
}
【问题讨论】: