I want to deprecate some, but not all possible enumeration values.
Enum constants are implicitly static and final and you can not change their value once created. Enum in Java provides type-safety and can be used inside switch statements like int variables.
Enums are exactly final inner classes that extends java. lang. Enum<E> . You cannot extend, override or inherit an enum .
We've learned that we can't create a subclass of an existing enum. However, an interface is extensible. Therefore, we can emulate extensible enums by implementing an interface.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With