Enum : a quick example

Enum was added in jdk 1.5. There are some corners where you can find the use of “public static final int vars” .  A quick example for the time starved. This lets you use the Enum as a type or get the numerical value out of it if needed, example below :

enum Ids {

  private int value;    

  private Ids(int value) {
    this.value = value;

  public int getValue() {
    return value;

Usage : 

Ids i = Ids.OPEN;
int i = Ids.OPEN.getValue();

// JDK makes it easy for Enum to be used as part of a switch statement
    case Ids.OPEN : //code for this section
    case Ids.CLOSE : // code for this section

Leave a comment

Filed under Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s