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 xxrequests 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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -