Java 5 Enum Example

Thursday, June 10th, 2010

Description

This simple example of a Java 5 Enum models a PREV/NEXT you might commonly see in a web app.

package foo.bar;

public enum PagingCriteriaDirection {
    NEXT("Next"), PREV("Previous");

    private String description;

    private PagingCriteriaDirection(String desc){
        description = desc;
    }

    public String getDescription() {
    	return description;
    }

    @Override
    public String toString() {
    	return description;
    }
}

You can leave a response, or trackback from your own site.

Tags:
Posted in: Development, Examples



One Response to “Java 5 Enum Example”

  1. Ibatis TypeHandlerCallback Enum Example Says:

    June 11th, 2010 at 12:30 pm

    [...] In this example I map a “prev” or “next” coming back from the DB (as “direction”) to the Enum described in this post. [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>