public interface Proposal { public static final enum STATUS { NEW , START , CONTINUE , SENTTOCLIENT }; }
Java does not allow an enum to be final
inside an interface, but by default every data member inside an interface is public static final
. Can anybody clarify this?
The members of the enum are constants, but the reference variable referring to enum values is just like any other reference variable, hence the need to mark them as final .
An enum type is implicitly final unless it contains at least one enum constant that has a class body. It is a compile-time error to explicitly declare an enum type to be final. Nested enum types are implicitly static.
An enum can, just like a class , have attributes and methods. The only difference is that enum constants are public , static and final (unchangeable - cannot be overridden). An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).
Because they are constants, the names of an enum type's fields are in uppercase letters. You should use enum types any time you need to represent a fixed set of constants.
Java does not allow you to create a class that extends an enum
type. Therefore, enums themselves are always final, so using the final
keyword is superfluous.
Of course, in a sense, enum
s are not final because you can define an anonymous subclass for each field inside of the enum descriptor. But it wouldn't make much sense to use the final
keyword to prevent those types of descriptions, because people would have to create these subclasses within the same .java file, and anybody with rights to do that could just as easily remove the final
keyword. There's no risk of someone extending your enum in some other package.
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