Terry Li Terry Li - 1 year ago 168
Java Question

Java how to access inner enum class

public class Constant {


public enum Status {



After compiling I got a class file named Constant$Status.class. The question is, how can I access the enum value. For instance, I want to get the string representation of the ERROR status.

Answer Source

You'll be able to access it elsewhere like

import package.name.Constant;
Constant.Status foo = Constant.Status.ERROR;


import package.name.Constant;
import package.name.Constant.Status;
Status foo = Status.ERROR;

To get the declared name of any enum element, use Enum#name():

Status foo = ...;
String fooName = foo.name();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download