我要扩展以下case class
:
case class Message[A](ackTo: ActorRef[Ack], msg: A)
我尝试过:
case class KafkaMessage() extends Message[KafkaHealthEvent]
with ServerHealthStreamer
case class SapMessage() extends Message[SapHealthEvent]
with ServerHealthStreamer
但是我不知道如何正确扩展它。整个类型定义:
object ServerStreamer {
sealed trait Ack
object Ack extends Ack
sealed trait ServerHealthStreamer
case class Message[A](ackTo: ActorRef[Ack], msg: A)
case class Init(ackTo: ActorRef[Ack]) extends ServerHealthStreamer
case class KafkaMessage() extends Message[KafkaHealthEvent]
with ServerHealthStreamer
case class SapMessage() extends Message[SapHealthEvent]
with ServerHealthStreamer
case object Complete extends ServerHealthStreamer
case class Fail(ex: Throwable) extends ServerHealthStreamer
}
如何正确扩展它?
答案 0 :(得分:3)
如评论中所述,您不能extend
和case class
。因此,只需将Message
设为普通的class
或trait
答案 1 :(得分:0)
您可以扩展案例类,但扩展对象不能是案例类本身,只能是类。此外,请注意被扩展的 case 类必须在扩展类的构造中初始化其属性:
class FeignOkHttpConfiguration
这里可以看到扩展案例类的值是在类构造中赋值的。