为什么即使我在函数中指定了参数的默认值,我也必须指定参数的值

时间:2018-09-05 18:28:28

标签: playframework-2.6

我有一个Action

 def index(signupMessage:String="") = addToken {
        silhouette.UserAwareAction { implicit request =>
        println(s"index action called with request ${utilities.printPlayHttpRequest(request)}")
        println(s"index page's argument "+signupMessage)
        val Token(name, value) = CSRF.getToken.get
        println(s"Token name ${name}, value ${value}")
        Ok(views.html.index(/*signupMessage:Option[String]*/messagesApi("app.title")(langs.availables(0))))
      }
    }

请注意,signupMessage具有默认值。

我正在如下routes.conf文件中使用它

GET / controllers.HomeController.index(signupMessage="") GET /home controllers.HomeController.index(signupMessage="") GET /home:signup controllers.HomeController.index(signup)

即使我为signupMessage指定了默认值,我也必须在调用index(signupMessage="")时指定它的值,因为如果我只执行index(),则会收到错误Using different overloaded methods is not allowed. If you are using a single method in combination with default parameters, make sure you declare them all explicitly.

为什么我不能使用参数的默认值?

0 个答案:

没有答案