I follow the instructions on Play! Framework Essentials, and sometimes I see action in controllers defined with def , and sometimes with val .
I know that def will re-evaluate the expression when called, and val will immediately evaluate the expression, but is there any difference in the context of the controller action?
Here is a sample code:
object Items extends Controller { val list = Action { implicit request => ... } val create = Action { implicit request => ... } def details(id: Long) = Action { implicit request => ... } def update(id: Long) = Action { implicit request => ... } }
As you said, it defwill re-evaluate the expression every time it is called, and valwill be evaluated when the object is created Items.
def
val
Items
, , def, , , , Action, , , ..
Action
, val, def.