-1

In play application I'm using "activate-framework". Enumerations I have to declare this way:

object State extends Enumeration {
case class State(value: Int) extends Val(value)
   val OPEN = State(0)
   val CLOSED = State(1)
}

Source: http://activate-framework.org/documentation/entity/

How can I get State from Int something like:

State.valueOf(1) <==== ??

In model I have a field state:

import model.State.State
case class Task(var name:String, var state:State)

it is State.State case class, how Can I convert Int to State.State class? When I do State(1) I receive State.Value not State.State class.

Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56
  • But when I'm trying to assign to field var state:State.State = State(1) I receive: "error: type mismatch; found : State.Value required: State.State" – Michał Jurczuk Mar 10 '14 at 16:05

2 Answers2

2
scala> State(1)
res0: State.Value = CLOSED
Marth
  • 23,920
  • 3
  • 60
  • 72
0

To be able to get value by name you have to declare enum using string constructor:

case class State(value: String) extends Val(value)
Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56