2013-05-01 137 views
0

我正在尝试对XMLMessage清单进行排序,而清单则来自Message。消息特征扩展了Ordered并提供基于时间戳的比较功能。然而,当我试着说:斯卡拉 - 订购清单

list.sorted 

错误说

error: diverging implicit expansion for type scala.math.Ordering[domain.XMLMessage] 
starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits 

我如何可以提供订购的消息,以便list.sorted将工作?谢谢

回答

1

sorted要求Ordering[XMLMessage],但您(通过implicits)只能提供Ordering[Message]Ordering是不变的,因此排序不能使用它。实现你想要的最简单的方法可能是:

list.sortBy(_: Message)