相关疑难解决方法(0)

java enum变量是静态的吗?

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;
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,两个操作的操作值都会发生变化.如何使用不同操作类型的两个Operations.SINGLE实例?

java enums

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

enums ×1

java ×1