users@jax-rs-spec.java.net

[jax-rs-spec users] Use "extensible enums" for HTTP codes, Mediatypes, Headers, Link Relation?

From: Thomas Koch <thomas_at_koch.ro>
Date: Fri, 16 Mar 2012 10:42:10 +0100

Another thought.

Bloch describes how to use enums and still have the possibility to kind of
"extend them" in Effective Java ed2 item 34. The trick is to have the enum
implement an interface and to refer to the interface instead of the enum type.

There are plenty of constants lists in JAX-RS. Have you considered using such
"extensible enums" instead, e.g. for HTTP codes, Mediatypes, Header names,
Link relations, HTTP methods?

There's already a type for MediaType. I think it would be nice to have types
for the other entities too. I'd especially like them for HTTPCode and
HTTPMethod to refer to them for dependency injection.

The provider method of my Preconditions interface from my earlier email for
example requires the HTTPMethod but currently needs to take it from the
Request class.

Best regards,

Thomas Koch, http://www.koch.ro