在以下情况下如何定义方法返回类型:
工作代码
def deleteInstance(model: String, uid: Long) = model match {
case "menu" => Model.all(classOf[Menu]).filter("uid", uid).get().delete()
case "articles" => Model.all(classOf[Articles]).filter("uid", uid).get().delete()
case "news" => Model.all(classOf[News]).filter("uid", uid).get().delete()
case "image" =>Model.all(classOf[Image]).filter("uid", uid).get().delete()
case "files" =>Model.all(classOf[Files]).filter("uid", uid).get().delete()
case _ => false
}
非工作代码:
class ModelManager{
def getModel(model: String) = {
model match{
case "menu" => classOf[Menu]
case "articles" => classOf[Articles]
case _ => false
}
def deleteInstance(model:String, uid: Long) = {
Model.all(getModel(model)).filter("uid", uid).get().delete()
}
}
}
引发的错误是:
递归方法getModel需要结果类型