I have a enum class as follows.
public enum Item {
COKE("Coke", 25), PEPSI("Pepsi", 35), SODA("Soda", 45);
private String name;
private int price;
private Item(String name, int price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public long getPrice() {
return price;
}
}
and a hashmap defined as follows
private Map<Item, Integer> inventory = new HashMap<Item, Integer>();
Do i need to override hashcode and equals in the enum Item class for inventory.put() and inventory.get() to work properly? If not, why?