在下面的代码中,我试图从 PLUS 常量输出作为 Operation 实例变量的符号的值。
但我无法访问该变量。
有什么问题?
public enum Operation {
PLUS("+", (x, y) -> {
System.out.println(symbol);
return x + y;
}),
MINUS("-", (x, y) -> x - y),
TIMES("*", (x, y) -> x * y),
DIVIDE("/", (x, y) -> x / y);
Operation(String symbol, DoubleBinaryOperator op) {
this.symbol = symbol;
this.op = op;
}
public String getSymbol() {
return symbol;
}
protected final String symbol;
private final DoubleBinaryOperator op;
public double apply(double x, double y) {
return op.applyAsDouble(x, y); …Run Code Online (Sandbox Code Playgroud)