Reputation: 155
Is it possible to use the @Deprecated
annotation on enum constants?
Upvotes: 4
Views: 3490
Reputation: 8387
Yes, put a @Deprecated
annotation on them (uppercase). For example:
public enum Status {
OK,
ERROR,
@Deprecated
PROBLEM
}
@Deprecated is an annotation that is read by the compiler, used to mark a method as deprecated to the compiler and will generate a deprecation compile-time warning if the method is used.
@deprecated is a javadoc tag used to provide documentation about the deprecation. You can use it to explain why the method was deprecated and to suggest an alternative. It only makes sense to use this tag in conjunction to the @Deprecated annotation.
Upvotes: 5
Reputation: 328735
If you check the javadoc, you will see the declaration:
@Target(value={CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PACKAGE,PARAMETER,TYPE})
which includes FIELD
. If you click on FIELD
you get to its javadoc which states:
Field declaration (includes enum constants)
So the answer is: yes it should work fine.
Upvotes: 6