【发布时间】:2015-03-10 03:22:54
【问题描述】:
我有一大堆模型要清理。所以基本上,模型看起来像;
case class ExampleModel(…) extends Model {
…
}
object ExampleModel {
def find = new Finder[Long, ExampleModel](classOf[Long], classOf[ExampleModel]) // very repetitive
…
}
现在,我一直在尝试定义一个 abstract class,它为我提供了一个伴随对象特定的 find 方法;
abstract class Findable[T: ClassTag] {
self: T => def find = new Finder[Long, T](classOf[Long], classOf[T])
}
但编译失败:
class type required but T found
解决这个问题的正确方法是什么?
【问题讨论】:
标签: scala inheritance abstract-class