Tag Archives: enum

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