📄 extendedoperation.java
字号:
// Subclass of extensible, serializable typesafe enum - Page 112
import java.io.*;
abstract class ExtendedOperation extends Operation {
ExtendedOperation(String name) { super(name); }
public static Operation LOG = new ExtendedOperation("log") {
protected double eval(double x, double y) {
return Math.log(y) / Math.log(x);
}
};
public static Operation EXP = new ExtendedOperation("exp") {
protected double eval(double x, double y) {
return Math.pow(x, y);
}
};
// The 4 declarations below are necessary for serialization
private static int nextOrdinal = 0;
private final int ordinal = nextOrdinal++;
private static final Operation[] VALUES = { LOG, EXP };
Object readResolve() throws ObjectStreamException {
return VALUES[ordinal]; // Canonicalize
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -