title: How can I call a super class method from a code block in a derived class?
body: <p>This question is somewhat hard to summarize. Following code block shows what I want to do.
  I have a base class like this:</p>
  
  <pre><code> `class Base {
     def methA:String="ook"
     def methB:Int=1
  }
  </code></pre>
  
  <p>Also I have a derived class, where I want each subclass method to call the super class method twice, compare the results and throw an exception on mismatch (this is for a test scenario).</p>
  
  <p>But if I write </p>
  
  <pre><code>class Derived extends Base {
  
    private def callDoublyAndCompare[T](fun:()=&gt;T) : T = {
        val fst=fun()
        val snd=fun()
        if(fst!=snd) throw new RuntimeException(s"Mismatch fst=$fst != snd=$snd")
        snd
    }
  
    override def methB:Int={
       callDoublyAndCompare(() =&gt; super[Derived].methB)
    }
  }
  </code></pre>
  
  <p>Then this will not compile. The only way out of this problem sofar has been to extract a method in class <em>Derived</em> which only calls the superclass' <em>methB</em> and to call this from the lambda call.</p>
  
  <p>Is there a better way?</p>