Deprecating a Java Enum Entry

Ran across this interesting tidbit about java enumerations: you can deprecate an entry. Although you’ll have to be careful if you have data tied to any legacy entries, in which case you are stuck with the entry or you’d have to do a data conversion if you decided to remove an entry.

Let’s say you have a Currency name enumeration and you want to get rid of nickels, you could deprecate nickels with the @Deprecated annotation until you have time to update everything to the new specs:

public enum Currency {

PENNY,
@Deprecated
NICKEL,
DIME,
QUARTER

};

CurrencyType deprecatedNickel = CurrencyType.NICKEL;

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>