我试图用一个匹配替换我的isInstanceOf检查,但它不起作用。斯卡拉匹配错误
在我的方法中,我检查一个树节点 - 如果它是一片树叶 - 我想立即将它返回到一个Vector中,如果不是,我继续使用该方法。
所以我原本:
//code here
if (common.isInstanceOf[LeafNode]) {
return Vector(common.asInstanceOf[LeafNode].data)
}
//code here
然后我试图取代它:
//code here
common match {
case leaf: LeafNode => return Vector(leaf.data)
}
//code here
,但我得到scala.MatchError。
约回报好一点,谢谢其实 – drozzy 2011-02-15 06:31:38
,如果你在你的函数返回语句,斯卡拉2.9编译器会强迫你明确说明函数的返回类型。不知道有关早期版本,虽然 – Aaron 2011-08-18 20:55:40