Possible Duplicate:
Interface/enum listing standard mime-type constants
Is there an enum (or something similar) which holds constants for the most common MIME types?
I'd like to deal with some constants rather than firing Strings here and there.
I must answer a resounding no because actually you can't. Enums have their own data type and each enum is essentially a new data type.
Enums are very powerful as they may have instance variables, instance methods, and constructors. Each enum constant should be written in capital letters. Every enum constant is by default internally public static final of type Enum declared.
The enum class body can include methods and other fields. The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared.
Can Enum extend a class in java? Enum cannot extend any class in java,the reason is, by default Enum extends abstract base class java.
There is not one in the JDK that I am aware of. But there is this class that you can probably start with.
Edit:
Now there is a better option I think. Using Guava's MediaType is a class that is maintained.
There cannot be an enum, since there is no closed set of possible values.
Several frameworks provide convenient classes that contain list of Strings. For example JAX-RS (jsr311) spec provides a class javax.ws.rs.core.MediaType.
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