【问题标题】:Strange implicit scala compile error奇怪的隐式scala编译错误
【发布时间】:2012-12-11 07:00:27
【问题描述】:

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

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 初学者,我只是坚持这一点。谁能给我一个线索?

【问题讨论】:

    标签: scala


    【解决方案1】:

    证据参数是函数的柯里化隐式参数,如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])

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 2016-01-23
      相关资源
      最近更新 更多