Cyclic definition of overriding

Alex Buckley alex.buckley at
Wed Jun 10 18:36:36 UTC 2015

On 6/10/2015 9:23 AM, Konstantin wrote:
> First of all, sorry for meaningless names. We can use I1, I2 and SubClass.

SubClass is not a good name because we'll end up saying "class SubClass, 
a subclass of class ..." which is obtuse. Also, the class in this 
example is NOT a subclass of interface I1 or I2. A class can only be a 
subclass of another class, not an interface.

> As I understand, you said that we should use chapter 9, not 8.
> Could you clarify, why can't I consider I1 with SubClass, which inherit
> method m2 from I2?
> Is it important, from what type is overriding?


interface I1 { void foo(); }
interface I2 extends I1 { void foo(); }
class C implements I1, I2 {}

C does not inherit foo() from I1 because there does exist a method foo() 
in another superinterface (I2) which overrides-from-I2 the foo() in I1.

C does inherit foo() from I2 because there is no method foo() in another 
superinterface (I1) which overrides-from-I1 the foo() in I2.

Someone might say "Who cares which foo() is inherited by C? Both foo() 
methods are the same." Prior to Java SE 8, that was a fair question. In 
Java SE 8, it's a poor question because the foo() methods can be 
default, and therefore have different behavior, and therefore it matters 
which one is inherited. For example:

interface I1 {
   default void foo() { System.out.println("I1"); }
interface I2 extends I1 {
   default void foo() { System.out.println("I2"); }
class C implements I1, I2 {}

You would really like this to compile (it does), and you would really 
like new C().foo() to print I2 (it does) rather than I1.

> May be jls-8.4.8-200-E should be:
> There exists no method m' that is a member of the direct superclassor a
> direct superinterface, D', of C (m distinct from m', D distinct from
> D'), such that m' from D' overrides the declaration of the method m.

Ummm, that's what 200-E says today.

> If there will be no mention of superinterfaces in this assertion, the
> problem would be solved.

I think you can see that methods in a family of superinterfaces do 
contribute to the methods inherited by a class, so it is important to 
mention superinterfaces here. Let's not go further down the road of 
rewriting assertions.


More information about the compiler-dev mailing list