def action = Action { request =>
if (true) {
return BadRequest("bad")
}
Ok("all ok")
}
What will be displayed as the result of requesting the action?
method action has return statement; needs result type
From Scala Reference:Syntax:
Expr1 ::= ‘return’ [Expr]
A return expression return e
must occur inside the body of some enclosing named
method or function.
The innermost enclosing named method or function in a source program, must have an explicitly declared result type, and the type of e must conform to it.
Syntax:
Expr1 ::= ‘return’ [Expr]
A return expression return e must occur inside the body of some enclosing named method or function. The innermost enclosing named method or function in a
source program, f, must have an explicitly declared result type, and the type of e must conform to it. The return expression evaluates the expression e and returns its value as the result of f. The evaluation of any statements or expressions following
the return expression is omitted. The type of a return expression is scala.Nothing.Syntax:
Expr1 ::= ‘return’ [Expr]
An apply method which is generated by the compiler as an expansion of an anonymous function does not count as a named function in the source program, and therefore is never the target of a return expression.
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати