ListenerEvent是某个库的类, 想要转化为它所代表的的ddl操作,通过implicit, 存在类型(通过定义T2DDL改成了上下文限定), 完成了特设多台
trait ToDDLModification[T <: ListenerEvent] {
def toDDLModification: DDLModification
}
object ToDDLModification{
type T2DDL[X] = X => DDLModification
implicit class ToDDL[T <: ListenerEvent : T2DDL](event: T) extends ToDDLModification[T] {
override def toDDLModification: DDLModification = {
implicitly[T2DDL[T]].apply(event)
}
}
implicit val alterParFunc: T2DDL[AlterPartitionEvent] = e => {
DDLModification("")
}
implicit val createDbFunc: T2DDL[CreateDatabaseEvent] = e => {
DDLModification("")
}
}
网友评论