Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It’s of course hard to guess but I think your class should <em>maybe</em> (you’d have to change quite a bit to make it actually work) look like this</p> <pre><code>class GridBase[T &lt;: DescripTypes](val myHex: T#HexT) { this: T =&gt; var testvar = 5 var testvar2 = "" def mymethod(var1: HexT) { testvar += var1.num1 } def method2(var1: SideT) { testvar2 = var1.sideString } } </code></pre> <p>In your example <code>mymethod</code> takes any <code>HexT</code> whereas I think you want to restrict it to the same outer class that <code>myHex</code> has.</p> <p>Depending on the use-case, (the self-type requires you to mix-in a sub-trait of <code>DescripTypes</code>), the following is more appropiate:</p> <pre><code>class GridBase[T &lt;: DescripTypes](val myHex: T#HexT) { var testvar = 5 var testvar2 = "" def mymethod(var1: T#HexT) { testvar += var1.num1 } def method2(var1: T#SideT) { testvar2 = var1.sideString } } </code></pre> <p>You’d have to specify the subclass of <code>DescripTypes</code> and could then use the type aliases defined in these subclasses.</p> <pre><code>val scenType = new ScenTypes val scenTypeHex = new scenType.HexT val scenTypeSide = new scenType.SideT val gb_st = new GridBase[ScenTypes](scenTypeHex) gb_st.mymethod(scenTypeHex) gb_st.method2(scenTypeSide) // and the same for some other subclass of DescribTypes val scenType2 = new ScenTypes2 val scenType2Hex = new scenType2.HexT val scenType2Side = new scenType2.SideT val gb_st2 = new GridBase[ScenTypes2](scenType2Hex) gb_st2.mymethod(scenType2Hex) gb_st2.method2(scenType2Side) // Does not compile: gb_st2.method2(scenTypeSide) </code></pre>
    singulars
    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. 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.
    3. 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