简体   繁体   中英

Scala: Generic Method

I can not find a solution to this problem:

This trait:

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

And this:

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

This object:

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

And this method:

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

The method does not compile. But I think you can see what I would like to achieve. What does the signature have to look like?

EDIT: Actually I do not care about "Schema" in the Method, it just has to be a valid BasicRepository.

EDIT2: Compilation Error (when calling the method, with AgnosticDriver.api being 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]

so thanks for the comments. I was too stupid to read to think about the easy failures.

I just passed the wrong arguments to "insertProfilePart" ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM