Scala self-typed trait and calling method on supertype -
lets have class this
class job(args:string) { def config:map[string,string] = ... }
i want create trait can mixed in class add more configuration options. did this
trait extraconfig { self:job => override def config = self.config ++ map("extra","config") }
unfortunately doesnt compile self.config becomes self recursive.
i tried doing
trait extraconfig extends job {}
but job taking constructor param , dont know how thread through.
what best way solve this?
you looking abstract override
modifier, use need explicitly extend job
class, in trait can use members of superclass:
class job(args:string) { def config:map[string,string] = map.empty } trait extraconfig extends job { abstract override def config = super.config ++ map("extra" -> "config") } val job = new job("name") extraconfig
Comments
Post a Comment