0

I have the following code:

ElasticService.delete(id) match {
case failure: RequestFailure => complete(StatusCodes.InternalServerError, failure.body.getOrElse("Unknown reason"))

case success: RequestSuccess[DeleteResponse] => {
  println(s"$id Deleted")
  .....
}

}

'delete' method is implemented as:

def delete(id: String): Response[DeleteResponse] = {
    client.execute {
      deleteById("myIndex", id)
    }.await
  }

This all works as expected. But if I modify match block by replacing DeleteResponse with DeleteByQueryResponse, I see that match still happens.

Why is it so? I see no hierarchical relationship between DeleteResponse and DeleteByQueryResponse.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 2
    Does this answer your question? [How to pattern match on generic type in Scala?](https://stackoverflow.com/questions/16056645/how-to-pattern-match-on-generic-type-in-scala) – Gaël J Oct 09 '21 at 17:19
  • 1
    You should get a compiler warning about type erasure. To put it simply: the generic type inside `RequestSuccess` is ignored by pattern match because it's not available at runtime. – Gaël J Oct 09 '21 at 17:21

0 Answers0