Scala:泛型方法
Scala: Generic Method
我找不到这个问题的解决方案:
这个特质:
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]]
该方法未编译。但我想你可以看到我想要实现的目标。签名必须是什么样子的?
编辑:实际上我不关心方法中的 "Schema",它只需要是一个有效的 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]
非常感谢您的评论。我太笨了,不读书,不去想容易的失败。
我刚刚将错误的参数传递给 "insertProfilePart" ...
我找不到这个问题的解决方案:
这个特质:
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]]
该方法未编译。但我想你可以看到我想要实现的目标。签名必须是什么样子的?
编辑:实际上我不关心方法中的 "Schema",它只需要是一个有效的 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]
非常感谢您的评论。我太笨了,不读书,不去想容易的失败。
我刚刚将错误的参数传递给 "insertProfilePart" ...