I have enum class
public enum CommandEnum {
ADD_ITEM {
{
this.command = new AddItemCommand();
}
};
protected Command command;
public Command getCurrentCommand() {
return command;
}
}
And class which try to get particular command
CommandEnum currentState = CommandEnum.valueOf(action.toUpperCase());
current = currentState.getCurrentCommand();
And how many copies was created of class AddItemCommand if I called this command 4 times for example?
Enum constants are public static final, so you will get the only one object every time. It’s very easy to discover it yourself.