I am the founder and CEO of Data Geekery GmbH, located in Zurich, Switzerland. With our company, we have been selling database products and services around Java and SQL since 2013. Ever since my Master's studies at EPFL in 2006, I have been fascinated by the interaction of Java and SQL. Most of this experience I have obtained in the Swiss E-Banking field through various variants (JDBC, Hibernate, mostly with Oracle). I am happy to share this knowledge at various conferences, JUGs, in-house presentations and on our blog. Lukas is a DZone MVB and is not an employee of DZone and has posted 241 posts at DZone. You can read more from them at their website. View Full User Profile

Syntax for Calling "super" in Java 8 Defender methods

  • submit to reddit

This is a very interesting discussion. How to reference default methods from implemented interfaces throughout the class / interface hierarchy?


interface K {
  int m() default { return 88; }

interface J extends K {
  int m() default { return K.super.m(); }
                        // ^^^^^^^^^^^^ How to express this?

Solution ideas:

  • K.super.m()
  • super.K.m()
  • ((K) super).m()
  • K::m()
  • K.default.m()
  • super<K>.m()
  • super(K).m()
  • super(K.class).m()
  • super[K].m()

Any other crazy ideas? See the discussion here:




Published at DZone with permission of Lukas Eder, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Qinxian Xiang replied on Sat, 2012/09/08 - 8:56pm

Why K.m not in sight? in the thread K.m simplest!

The key point is: K.m indicate direct subclass of K used. and JVM need maybe need new invokespecialinterface instruction!huf!

Konrad Malawski replied on Sun, 2012/09/09 - 2:15pm

I find Scala's solution to this pretty elegant (as with most things that java language design now struggles with due those default methods in interfaces (traits, duh!)):

trait M { def m = 88 }
trait K { def m = 44 }
trait J extends K with M {
  override def m = super.m // M#m, as it's the last mixin

  assert { super[K].m == 44 } 
  assert { m == 88 }

This could be easily adapted to Java syntax: super<K>.something

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.