2017-04-19 12 views
0

として、私はケースクラスのパラメータは、一般的なことができるようにしようとしています:有界ジェネリック型ケースクラスパラメータ

trait RequestEntityMarshallable 

case class ImportConfirmMessage(bla: String) extends RequestEntityMarshallable 

case class Req(entity: _ <: RequestEntityMarshallable) 

私はentity: _ <: RequestEntityMarshallableunbound wildcard typeコンパイル・エラーが発生しますが。これを行う正しい方法は何ですか?

答えて

1

そのため、この

case class Req[A <: RequestEntityMarshallable](entity: A) 
+0

感謝しています。 'Req'を他の関数のパラメータとして使うときに何を変更する必要があります。たとえば、 'def send(req:Req):Future [HttpResponse]'は、RequestEntityMarshallableの任意のサブタイプに対するReqインスタンスで呼び出すことができます。 – novon

+1

私は 'def send [T <:RequestEntityMarshallable](req:Req [T]):Future [HttpResponse]' – novon

+0

@novon nice :)で作業していると思います。 – pamu

関連する問題