Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You code is wrong, it won't even compile. </p> <p>Your <code>GenericEchoer</code> cannot be a <code>class</code>, cause your <code>content</code> member is abstract, or you should init this with a default value:</p> <pre><code>class GenericEchoer[T &lt;: AnyRef] { var content: T = _ def echo: String = "Echo: " + T.toString } </code></pre> <p>You can't write <code>T.toString</code>, i guess you wanted <code>content.toString</code>. You can't pass <code>Int</code> to it, cause <code>Int</code> has <code>AnyVal</code> as its supertype, and your upper bound of <code>T</code> is <code>AnyRef</code>.</p> <p><code>self.content</code> in <code>Substitution</code> is also illegal, you should:</p> <p>1) make <code>self</code> as a selftype:</p> <pre><code>trait Substitution[T &lt;: AnyRef] extends GenericEchoer[T] { self =&gt; def substitute(newValue: T) = { self.content = newValue } } </code></pre> <p>2) Replace it with <code>this</code> 3) Just leave <code>{ content = newValue }</code></p> <p>As for your problem. No it's not possible. I can suggest you replace <code>class</code> with a <code>trait</code> and type constructor with an abstract type member:</p> <pre><code>trait GenericEchoer { type T &lt;: AnyRef var content: T = _ def echo: String = "Echo: " + content.toString } trait Substitution extends GenericEchoer { def substitute(newValue: T) { content = newValue } } val enchoer = new GenericEchoer with Substitution { type T = String } </code></pre> <p>or better</p> <pre><code>val enchoer = new GenericEchoer with Substitution { type T = String var content = "Hello" // either case it will be null } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload