j3d
j3d

Reputation: 9724

Scala: How to get an Enumeration "Value" from a literal

Given to following Enumeration...

object TokenType extends Enumeration {

  type TokenType = Value

  val Activation = Value("activation")
  val Authentication = Value("authentication")
  val Reset = Value("reset")
} 

... I get the a value as a string like this:

scala> val str = Reset.toString
str: String = reset

But how can I get a TokenType.Value starting from the string reset?

scala> val v: TokenType = ???

Thanks.

Upvotes: 1

Views: 813

Answers (1)

Ashalynd
Ashalynd

Reputation: 12563

try this: TokenType.withName("reset")

Upvotes: 3

Related Questions