【问题标题】:Scala: Generic MethodScala:通用方法
【发布时间】:2015-06-18 19:15:05
【问题描述】:

我找不到这个问题的解决方案:

这个特质:

trait BasicRepository[Schema <: Table[Entity] with Identifiable[Entity], Entity] 

还有这个:

trait ProfilePartRepository[Schema <: Table[Entity] with ProfilePart[Entity], Entity] 

这个对象:

 object PhoneNumberRepository extends BasicRepository[PhoneNumbers, PhoneNumber] with ProfilePartRepository[PhoneNumbers, PhoneNumber] {

还有这个方法:

def insertProfilePart[Schema <: Table[Entity] with Identifiable[Entity], Entity](repository: BasicRepository[Schema, Entity], entities: Seq[Entity]) : Seq[Future[Int]]

该方法无法编译。但我想你可以看到我想要实现的目标。签名应该是什么样子的?

编辑:实际上我并不关心方法中的“架构”,它必须是一个有效的 BasicRepository。

EDIT2:编译错误(调用方法时,AgnosticDriver.api 为 slick.driver.JdbcDriver):

 inferred type arguments [persistence.slickSchemas.PhoneNumbers,Product with Serializable] do not conform to method insertProfilePart's type parameter bounds [Schema <: persistence.AgnosticDriver.api.Table[Entity] with persistence.slickSchemas.Identifiable[Entity],Entity]

【问题讨论】:

  • 编译错误是什么?
  • 添加到问题:推断类型参数 [persistence.slickSchemas.PhoneNumbers,Product with Serializable] 不符合方法 insertProfilePart 的类型参数边界 [Schema <: persistence.agnosticdriver.api.table with persistence.slickschemas.identifiable>
  • 通过观察这个问题,我不明白为什么它会给你带来困难。是否可以创建重现错误的代码的独立(可编译)版本?然后有人至少可以尝试一下,看看发生了什么。

标签: scala types slick


【解决方案1】:

非常感谢 cmets。我太笨了,没有去思考简单的失败。

我刚刚将错误的参数传递给“insertProfilePart”...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 2012-07-28
    • 2023-04-07
    • 2016-12-25
    • 2016-07-01
    • 1970-01-01
    • 2011-06-26
    相关资源
    最近更新 更多