Raffi Khatchadourian Raffi Khatchadourian - 3 months ago 8
Java Question

Why can't I reference super in a default method in Java 8 enhanced interfaces?

It seems that all references to

super
are disallowed in interfaces, which would include default methods of enhanced interfaces. If the interface extends another interface and the default method overrides another default method in that interface, wouldn't it be conceivable that I may have a use case to call the overridden method?

Answer

Because interfaces allow for multiple inheritance. Allowing for super in default implementations would therefore introduce the famous diamond problem (see eg. http://www.programmerinterview.com/index.php/c-cplusplus/diamond-problem/).

Comments