0

我有枚举类

public enum CommandEnum {       

    ADD_ITEM {
        {
            this.command = new AddItemCommand();
        }
    };

    protected Command command;

    public Command getCurrentCommand() {
        return command;
    }
}

以及试图获取特定命令的类

CommandEnum currentState = CommandEnum.valueOf(action.toUpperCase());
current = currentState.getCurrentCommand();

AddItemCommand例如,如果我调用此命令 4 次,则创建了多少类副本?

4

1 回答 1

1

Enum 常量是 public static final 的,所以每次你只会得到一个对象。自己很容易发现它。

于 2012-08-23T10:16:49.107 回答