Does removing a redundant superinterface from a Java class break binary compatibility?

70 views Asked by At

In the following example:

interface I {
    int F = 1;
}
class A extends B implements I { ... }
class B implements I { ... }

the implements I on class A is redundant. If I remove it, does it break binary compatibility?

Background of the question: If I call getFields() on class A, I get the public field F from the interface I, but if I remove the redundant implements I, I no longer get field F.

1

There are 1 answers

0
queeg On

Let's add a class C to the example. So you have

interface I {
    int F = 1;
}
class B implements I { ... }
class A extends B implements I { ... }
class C extends B { ... }

I rearranged them so the superclass is on top.

Since the superclass B implements I, and C is similar to B I'd expect that it also implements I. With that, the implements I on class A should be redundant and can be removed.

On the other hand, if you remove the implements I on class B, it would have impact on C which also would no longer implement I. So the implements I on B is not redundant, as it mandates that B and all subclasses do implement I.