Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an enum with MIME Types in Java? [duplicate]

Tags:

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.

like image 235
Fabian Barney Avatar asked Oct 26 '11 14:10

Fabian Barney


People also ask

Can enum contain different types?

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.

Do enums have instances?

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.

Can Java enum have methods?

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 abstract class Java?

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.


2 Answers

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.

like image 72
Amir Raminfar Avatar answered Oct 22 '22 15:10

Amir Raminfar


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.

like image 27
Tarlog Avatar answered Oct 22 '22 15:10

Tarlog