Best way to create a Unique ID field for an enum
Posted
by jax
on Stack Overflow
See other posts from Stack Overflow
or by jax
Published on 2010-05-26T15:57:54Z
Indexed on
2010/05/26
16:01 UTC
Read the original article
Hit count: 149
java
What is the best way to get a Unique ID from an ENUM that will stay consistent between repeated execution of the program?
Currently I am doing this manually by passing an ID to the enum constructor. I don't really want to do this is I can help it.
Another option would be to use a static field that gets incremented for each enum value. The problem is that if later I decide to move the enum fields around or delete some this will cause problems with my program as the ID will be saved into user preferences.
The ID can be any basic type or a String.
© Stack Overflow or respective owner