Overriding issues in Scala -
i let code speak:
import scala.concurrent.future trait somerequest trait someresponse trait apistandard { def apicall[req <: somerequest, resp <: someresponse](request: req): future[resp] } case class xxrequest() extends somerequest case class xxresponse() extends someresponse class xxstandard extends apistandard { override def apicall(request: xxrequest): future[xxresponse] = ??? }
basically have couple of data traits (somerequest, someresponse) , behaviour trait apistandard. there case classes xxrequest , xxresponse override data traits. trying create concrete implementation of of apistandard called xxstandard. it's not syntactically correct. being scala beginner, can't understand why.
please throw light.
thanks.
apistandard defines method apicall
accepts parameter more flexible xxstandard
provides.
to illustrate,
if have
val something: apistandard = ???
you know can call
val req: somerequest something(req)
if ???
able new xxstandard()
, , xxstandard
accepts xxrequest
s it's argument apicall, broken: there no way know req in fact xxrequest
, , indeed, doesn't have one.
furtunately, doesn't compile, because apicall
in xxstandard
can't implement apistandard.apicall
.
to make xxstandard
can subtype of apistandard, apicall in xxstandard has take type declared in trait, or supertype of argument.
tl;dr:
methods contravariant in parameter type.
Comments
Post a Comment