Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

get instance of Enum from name

800455Mar 3 2009 — edited Mar 3 2009
I have to get the current instance of an Enum based on the classname. How do i acheive this.
this is what I am trying at the moment
   Enum clzz = (Enum) Class.forName(className).cast(Enum.class);
and enum declaration is this
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ngsmis.demo;

public enum PhaseType implements GenericEnum{
  
  NURSERY( "NY", "Nursery"),
  MIDDLE_MP( "MP", "Middle(Deemed Primary)"),
  MIDDLE_MS( "MS", "Middle(Deemed secondary)"),
  SECONDARY( "SY", "Secondary"),
  SPECIAL( "SP", "Special"),
  EARLY_YEAR( "EY", "Early Year Setting"),
  PR_UNIT( "PR", "People Referral Unit"),
  NO_ESTABLISHMENT( "NO", "No Establishment(For children not on any establishment roll)"),
  PRIMARY( "PY", "Nursery");

  private final String typeId;

  private final String name;

  private PhaseType(String typeId, String name) {
    this.typeId = typeId;
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public String getTypeId() {
    return typeId;
  }
}
the whole point is to be able to call the getTypeID method based on the Enum found.
any form of help will be gratefully appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2009
Added on Mar 3 2009
21 comments
1,510 views