Is it possible to deprecate some of the values of a Java enum and if so, how?
Yes, put a @Deprecated annotation on them. For example:
enum Status {
OK,
ERROR,
@Deprecated
PROBLEM
}
You can also add a JavaDoc @deprecated
tag to document it:
enum Status {
OK,
ERROR,
/**
* @deprecated Use ERROR instead.
*/
@Deprecated
PROBLEM
}
public enum Characters {
STAN,
KYLE,
CARTMAN,
@Deprecated KENNY
}
Just tried it eclipse, it works:
public class Test {
public static void main(String[] arg) {
System.err.println(EnumTest.A);
System.err.println(EnumTest.B);
}
public static enum EnumTest {
A, @Deprecated B, C, D, E;
}
}