This is basically what I’m trying to do:
enum Animal { CAT, FISH }
enum color { RED, GREEN }
int weight = 10
int IQ = 200
AnimalPrice.put((Animal.CAT, Color.GREEN, weight,IQ) , 5)
i.e. the price of a green cat that weights 10 pounds and has 200 iq is 5 dollars.
Is there a way to do this in java? I only got as far as using lists of integer as keys, but nothing about using enum types
There are 2 ways I would consider doing:
1 create the keys as the string concatanation of those 4 values
2 create an object made up of those values and create a custom equals and hashCode method
I would favor the second approach as it’s much more robust and future proof.
Use example: