shaz
shaz

Reputation: 2387

how can I initialize an enum from an Int or Byte?

I have an enum like this:

object Ops extends Enumeration {
  val one = Value(0x01)
  val two = Value(0x02)
  val three = Value(0x03)
  val four = Value(0x04)
}

I want to say

Byte someByte = functionThatReturnsAByte
val op = Ops.valueOf(someByte)

The only method close is withName which only takes a String.

Upvotes: 7

Views: 4974

Answers (1)

Rex Kerr
Rex Kerr

Reputation: 167901

Ops(someByte)

will do the trick.

Upvotes: 17

Related Questions