0

I have the following case class that I would like to extend:

case class Message[A](ackTo: ActorRef[Ack], msg: A) 

I've tried:

case class KafkaMessage() extends Message[KafkaHealthEvent]
    with ServerHealthStreamer

case class SapMessage() extends Message[SapHealthEvent]
    with ServerHealthStreamer

But I do not know, how to extend it correctly. The whole type definition:

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

}

How to extend it correctly?

2
  • You don't mention it, but I assume you're getting an error because you can't extend a case class and make another case class with it? Anyway, since you seem to be streaming, why not use akka streams directly? Commented Jul 14, 2019 at 17:50
  • 4
    case class is not used for inheritance or implementing traits Commented Jul 14, 2019 at 17:50

2 Answers 2

3

As explained in the comments, you can't extend a case class. So just make Message a normal class or trait

Sign up to request clarification or add additional context in comments.

Comments

0

You can extend a case class but the extended object cannot be a case class itself, only a class. Additionally, note that the case class which is being extended must have its properties initialised in the extending class' construction:

// Let KafkaActorRef extend ActorRef[Ack]
class KafkaMessage(kafkaActorRef: KafkaActorRef) extends Message[KafkaHealthEvent](kafkaActorRef, "someMessage")

Here you can see that the values of the extended case class are assigned in the class construction.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.