Method Bodies in Interfaces -- Why Not?

David Walend david at
Tue Mar 10 16:38:11 PDT 2009

A lot of us spend energy dealing with the fact that we can not add
methods to interfaces. We can't add methods to interfaces because
everything that implements those interfaces would break. We could get
around that by letting interface-defined methods have method bodies.
The resulting problem is that the compiler would not be able to choose  
between or order method bodies with the same signature. (As I  
understand it, that's why interfaces can't have method bodies.)

It's modestly rare for classes to inherit two interfaces that define
methods with the same signature in the wild. What happens if the JLS
were to relax the constraint?

I imagine a few options:

With multiple inheritance, if different implemented interfaces define
bodies for methods with the same signature then:

1) Give the developer a compile error or
2) Inherit neither method body and force the developer to implement
something himself or
3) Inherit neither method body, force the developer to implement
something himself, and give him some way to access to all the inherited

That would let us out of some of our more painful contortions. What  
are the holes in that idea?


david at

More information about the coin-dev mailing list