奇怪的隐式scala编译错误

时间:2012-12-10 22:30:24

标签: scala

我在抽象类中定义了这个方法:

abstract class RichTable[T](name: String) extends Table[T](name) {
    def insert(model : T) = Database { implicit db: Session =>
    *.insert(model.copy(id = getNextId(classOf[T].getSimpleName())))
  }
  //other methods which are fine
}

它(model.copy)说:

could not find implicit value for evidence parameter of type scala.slick.lifted.TypeMapper[T]

我根本不知道如何解决这个问题。我是scala初学者,我只是坚持这个。有人能给我一些线索吗?

1 个答案:

答案 0 :(得分:0)

证据参数是函数的curried隐含参数,如model.copy(id)(implicit typeMapper)中所示。您需要声明implicit val typeMapper: scala.slick.lifted.TypeMapper[T] = something。在model.copy来源中搜索F3。

修改

不太对,改变def insert(model: T) to def insert[T: ClassManifest](model: T)应该可以解决问题。为什么呢?

在函数内部,使用classOf[T],但实际类型的T在运行时被删除,并且不清楚应该调用哪个类getSimpleName()。因此,您应声明绑定了ClassManifest的类型参数,并且应自动添加适当类型的隐式参数[T](model: T)(implicit evidence$1: ClassManifest[T])

相关问题