For example, I have:
Action enum:
public enum Action{
Pour, Mix, Shake, Add;
public Ingredient ingredient;
public String toString() {
return super.toString() + " " + this.ingredient.toString();
}
}
Code example:
Ingredient [] ingredients1 = {
new DrinkingIngredient("Vodka", 50, 20),
new DrinkingIngredient("Tomato Juice", 120, 0),
new DrinkingIngredient("lemon juice", 10, 0),
new Component("Ice", 380),
new Component("Celery", 15),
};
Action act1 = Action.Add;
act1.ingredient = ingredients1[0];
Action act2 = Action.Mix;
act2.ingredient = ingredients1[1];
Action act3 = Action.Mix;
act3.ingredient = ingredients1[2];
Action act4 = Action.Shake;
Action act5 = Action.Add;
act5.ingredient = ingredients1[3];
Action act6 = Action.Add;
act6.ingredient = ingredients1[4];
I know this is not properly the best example I could do. Sorry about that, but I can explain that all Action enums have the same property value as the last one act6. So I can assume that the same enums in Java cannot live at once. Am I right? What should I do in that situation?
And yeah, after that:
System.out.print(act1);
I get: "Add Celery" just like the last one act6 instead "Add Vodka" as I expected