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