Hi there,
I am using some info from a database and assigning it to the various instance variables of an object. Mostly the info from the database is a
String, so I have very simple setter methods for these that take the String from the ResultSet and assign it to the relevant String instance variables of my object.
So far so good. What I've come unstuck on is that one of my object's instance variables is a reference to an enum, which I want to use as it's been suggested to me that it would make my code more readable. This can't be stored (I don't think) in a database, so I thought I could just store an int in the database and use this int as an argument to my object's setter method, which has code that uses that int as the index in the enum.
I've read up on enums and looked at the docs, and none of the methods allow you to say "I want the enum at index 2", which seems a bit odd to me as I would have thought lots of people would want to do that. Does anybody know if this is possible?
I think I could create an EnumMap with an int value as the key and the corresponding Enum as the value and use the EnumMap's get(Object key) method to return the enum, but this seems very long winded to me and I would be grateful for a second opinion.
Thanks in advance.
Joe