How can I initialize an enum from Int or Byte?

I have an enumeration 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 close method is withName, which only accepts a string.

+6
source share
1 answer
 Ops(someByte) 

will do the trick.

+14
source

Source: https://habr.com/ru/post/945509/


All Articles