public enum Operations {
SINGLE,
MULTIPLE;
private Type operation;
public void setOperation(Type operation) {
this.operation = operation;
}
public Type getOperation() {
return operation;
}
public static void main(String[] args) {
Operations oper1 = Operations.SINGLE;
oper1.setOperation(Type.GET);
Operations oper2 = Operations.SINGLE;
oper2.setOperation(Type.POST);
System.out.println(oper1.getOperation());
System.out.println(oper2.getOperation());
}
}
enum Type {
POST,
GET;
}
在上面的代码中,两个操作的操作值都会更改。我如何拥有两种不同操作类型的Operations.SINGLE实例?Java枚举变量是静态的吗?
如果您告诉我们打印到标准输出的内容,您的问题会更容易理解。 (我假设它打印两次“POST”?) –
SINGLE相当于public static final操作SINGLE = new操作(“SINGLE”,0) – Blackbelt