Scala,写抽象方法

时间:2014-05-05 17:03:43

标签: scala methods abstract

我想知道是否有办法为类似的类编写抽象方法。我有几个课程有一个"体重"例如,我不会将此方法应用于不同类的列表。有没有办法可以做到这一点?

def addPersons (a: List[Person], b:List[Person], bc:List[Person]): Int =
    if (a.isEmpty) 0
    else if (b.isEmpty) addPersons (a.tail, bc, List[Person]())
    else if (a.head == b.head) a.head.weight + addPersons(a.tail, bc ++ b, List[Person]())
    else addPersons(a, b.tail, b.head :: bc)

0 个答案:

没有答案