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