1

I need get field values of enum constant.

For example I have this enum:

public enum TestEnum {
  AAA("text 1", 10),
  BBB("text 2", 20);

  private final String text;
  private final int weight;

  TestEnum(String text, int weight) {
    this.text = text;
    this.weight = weight;
  }

  public String getText() {
    return this.text;
  }

  public String getWeight() {
    return this.weight;
  }
}

Enum constants are accessible via method enumConstants().

How can I get declared values for conrete enum constant? (I need information that enum constant AAA has 'text 1' for field text and 10 for field weight).

0 Answers0