-
1 votesanswersviews
带底层类型的类型参数 - Scala
假设我有一个 A 类型的特征,它是 Any 的子类,还有一个名为 nextState 的方法,它与参数具有相同的类型 . trait GameEnvironment { type A <: Any def nextState(state: A, input: Int): (A, Boolean) } 然后通过名为 Tetris 的类扩展此特征,该类将覆盖类型成员 A 和方法 nex... -
1 votesanswersviews
具有特征实现的Scala Generics -
我想构建一个消息传递Queue Consumer,它现在只有一个Kafka实现,但是稍后,它也可以有其他实现 . trait MessagingQueueConsumer { def consume[B <: NotificationConsumerRecords](topic: String, userNames: List[String]): TrieMap[String, B] ... -
2 votesanswersviews
模式匹配在scala中的通用抽象类型
我有一个自递归类型: trait Problem[P <: Problem[P]] { type Solution } 现在,我想在 P#Solution 上进行模式匹配 . 设's assume we'在 case class Foo[P <: Problem[P]]() 内: case ExampleCaseClass(s: P#Solution) if conditionA...