2
votes

I have an original Java enumeration class, which I can get the corresponding integer value using:

Integer blackInteger = ColorEnum.BLACK.getValue()

public enum ColorEnum {

    BLACK(0), BLUE(1), RED(2);

    private int value;

    private ColorEnum(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}

I then tried to write the enum class in Scala:

object ColorEnum extends Enumeration {
  val BLACK, BLUE, RED = Value
}

I am wondering how do I get the integer value of ColorEnum.BLACK in Scala?

Thanks a lot!

1
See also this answer. - senia

1 Answers

3
votes

Use id like so:

ColorEnum.BLACK.id

Enumeration.Value in the Scaladoc.