ntviet18
ntviet18

Reputation: 792

How to create generic constraint based on dependent type?

I have the following classes

trait Identifiable 


case class Address extends Identifiable


abstract class AbstractTable[T] {
  type TableElementType
}


class TableQuery[E <: AbstractTable[_]]


class Addresses(tag: Tag) extends Table[Address](tag, "addresses")

How to make the

abstract class AbstractOptionBaseRepsitory[T <: AbstractTable[_]]

accept only T where T#TableElementType is a subclass of Identifiable

Upvotes: 1

Views: 49

Answers (1)

Dima
Dima

Reputation: 40510

How about

 abstract class IdentifiableAbstractTable[T] extends AbstractTable[T] {
    type TableElementType <: Identifiable
 }

 abstract class AbstractOptionBaseRepository[T <: IdentifiableAbstractTable[_]]

Upvotes: 1

Related Questions