title: Method References to Super Class Method
body: <p>How to use method references to refer to super class methods?</p>
  
  <p>In Java 8 you can do <code>SubClass.super::method</code>.</p>
  
  <p>What would be the syntax in Kotlin?</p>
  
  <p>Looking forward to your response!</p>
  
  <p><s><strong>Conclusion</strong></p>
  
  <p>Thanks to Bernard Rocha!
  The syntax is <code>SubClass::method</code>.</p>
  
  <p>But be careful. In my case the subclass was a generic class. Don't forget to declare it as those: </p>
  
  <p><code>MySubMap&lt;K, V&gt;::method</code>.</s></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It still doesn't work in Kotlin.</p>
  
  <p>Hers's an example in Java 8 of a method reference to a super class method:</p>
  
  <pre><code>public abstract class SuperClass {
      void method() { 
          System.out.println("superclass method()");
      }
  }
  
  public class SubClass extends SuperClass {
      @Override
      void method() {
          Runnable superMethodL = () -&gt; super.method();
          Runnable superMethodMR = SubClass.super::method;
      }
  }
  </code></pre>
  
  <p>I'm still not able to do the same in Kotlin...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is an example how I tried to achieve it in Kotlin:</p>
  
  <pre><code>open class Bar {
      open fun getString(): String = "Hello"
  }
  
  class Foo : Bar() {
  
      fun testFunction(action: () -&gt; String): String = action()
  
      override fun getString(): String {
          //this will throw an StackOverflow error, since it will continuously call 'Foo.getString()'
          return testFunction(this::getString)
      }
  }
  </code></pre>
  
  <p>I want to have something like that:</p>
  
  <pre><code>...
      override fun getString(): String {
          //this should call 'Bar.getString' only once. No StackOverflow error should happen.
          return testFunction(super::getString)
      }
  ...
  </code></pre>
  
  <p><strong>Conclusion</strong></p>
  
  <p>It's not possible to do so in Kotlin yet.</p>
  
  <p>I submitted a feature report. It can be found here: <a href="https://youtrack.jetbrains.com/issue/KT-21103" rel="nofollow noreferrer">KT-21103 Method Reference to Super Class Method</a></p>