我在学习Scala游戏框架教程时,遇到了这样一段让我困惑的代码:
def newTask = Action { implicit request =>
taskForm.bindFromRequest.fold(
errors => BadRequest(views.html.index(Task.all(), errors)),
label => {
Task.create(label)
Redirect(routes.Application.tasks())
}
)
}
所以我决定调查一下,看到了这个帖子。
我还是不明白。
这两者的区别是什么:
implicit def double2Int(d : Double) : Int = d.toInt
and
def double2IntNonImplicit(d : Double) : Int = d.toInt
除了它们有不同的方法名之外。
什么时候应该使用隐式,为什么?