What is the difference between a default (interface) method and a regular abstract method, and how do default methods affect interface evolution?
Last updated
An abstract method has no body and every implementer must supply one. Adding one to a published interface breaks existing implementers.
A default method (
defaultin Java) carries a body in the interface. Implementers inherit it and may override it, so interfaces can evolve backwards-compatibly (e.g. Java 8 addingstream()toCollection).Caveat: if two interfaces supply the same default method (diamond problem), the class must override it explicitly.