If your enumeration space is dense, that is, there are not many unused values, you can use the toString () and valueOf () methods. Name your values โโthe common string prefix, then attach the prefix before using valueOf () and split it after using toString (). This has the disadvantage that you will have to convert to a numerical value if it is stored in your database.
Alternatively, you can add common conversion methods and assign the value of your database to a specific enumeration value.
Both of these methods have the advantage of using the design of enumeration classes.
There is a lot of good bending information about enums (and Java in general) at http://mindprod.com/jgloss/enum.html .
Although, if you do the right job, there is nothing wrong.
source share