方法結果我現在有重構VAL在編譯時錯誤
def list(node: NodeSeq): NodeSeq = {
val all = Thing.findAll.flatMap({
thing => bind("thing", chooseTemplate("thing", "entry", node),
"desc" -> Text(thing.desc.is),
"creator" -> thing.creatorName.getOrElse("UNKNOWN"),
"delete" -> SHtml.link("/test",() => delete(thing), Text("delete"))
)
})
all match {
case Nil => <span>No things</span>
case _ => <ol>{bind("thing", node, "entry" -> all)}</ol>
}
}
,我試圖將它重構到
def listItemHelper(node: NodeSeq): List[NodeSeq] = {
Thing.findAll.flatMap({
thing => bind("thing", chooseTemplate("thing", "entry", node),
"desc" -> Text(thing.desc.is),
"creator" -> thing.creatorName.getOrElse("UNKNOWN"),
"delete" -> SHtml.link("/test",() => delete(thing), Text("delete"))
)
})
}
def list(node: NodeSeq): NodeSeq = {
val all = listItemHelper(node)
all match {
case Nil => <span>No things</span>
case all: List[NodeSeq] => <ol>{bind("thing", node, "entry" -> all)}</ol>
case _ => <span>wtf</span>
}
}
,但我得到以下。我追蹤了所有的返回類型,我沒有看到我的重構與內部發生的情況有什麼不同。我甚至嘗試添加更多的匹配案例(正如你可以在重構代碼中看到的)來確保我選擇了正確的類型。
/Users/trenton/projects/sc2/supperclub/src/main/scala/com/runbam/snippet/Whyme.scala:37: error: overloaded method value -> with alternatives [T <: net.liftweb.util.Bindable](T with net.liftweb.util.Bindable)net.liftweb.util.Helpers.TheBindableBindParam[T] <and> (Boolean)net.liftweb.util.Helpers.BooleanBindParam <and> (Long)net.liftweb.util.Helpers.LongBindParam <and> (Int)net.liftweb.util.Helpers.IntBindParam <and> (Symbol)net.liftweb.util.Helpers.SymbolBindParam <and> (Option[scala.xml.NodeSeq])net.liftweb.util.Helpers.OptionBindParam <and> (net.liftweb.util.Box[scala.xml.NodeSeq])net.liftweb.util.Helpers.BoxBindParam <and> ((scala.xml.NodeSeq) => scala.xml.NodeSeq)net.liftweb.util.Helpers.FuncBindParam <and> (Seq[scala.xml.Node])net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.Node)net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.Text)net.liftweb.util.Helpers.TheBindParam <and> (scala.xml.NodeSeq)net.liftweb.util.Helpers.TheBindParam <and> (String)net.liftweb.util.Helpers.TheStrBindParam cannot be applied to (List[scala.xml.NodeSeq])
case all: List[NodeSeq] => <ol>{bind("thing", node, "entry" -> all)}</ol>
^
之前出現了編譯錯誤,所以沒有警告b/c。 – Trenton 2009-11-14 23:22:45