Scala: override a concrete member with an abstract one -


i'm trying override trait member abstract one, seems straightforward won't compile.

here's boiled down example of i'm trying do:

// not code: trait base {   val x = new t {}   trait t {} }  // code: trait sub extends base {   // compile error; see below   override val x: t2    // compiles, doesn't force `impl` implement `x` //  override val x: t2 = null    trait t2 extends t {     val someaddition:   } }  object impl extends sub {   // should forced implement `x` of type `t2` } 

here's compiler error:

error:(7, 7) overriding value x in trait sub of type sub.this.t2;  value x in trait base of type sub.this.t has incompatible type;  (note value x in trait sub of type sub.this.t2 abstract,   , therefore overridden concrete value x in trait base of type sub.this.t) trait sub extends base {       ^ 

a technique can think of use different name abstract member , getting concrete member call 1 instead.

trait sub extends base {   val y: t2   override val x = y 

there's interesting discussion on in java land.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -