gpt4 book ai didi

java - java枚举变量是静态的吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:58:49 34 4
gpt4 key购买 nike

<分区>

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 实例?

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com