After introducing Default Method, it seems that interfaces and abstract classes are same. However,
they are still different concept in Java 8.
Abstract class can define constructor. They are more structured and can have a state associated with
them. While in contrast, default method can be implemented only in the terms of invoking other interface methods,
with no reference to a particular implementation's state. Hence, both use for different purposes and choosing
between two really depends on the scenario context.
Default methods in Java interface enables interface evolution. Given an existing interface, if
you wish to add a method to it without breaking the binary compatibility with older versions of the interface,
you have two options at hands: add a default or a static method. Indeed, any abstract method added to the interface
would have to be implemented by the classes or interfaces implementing this interface.
A static method is unique to a class. A default method is unique to an instance of the class.
If you add a default method to an existing interface, classes and interfaces which implement this interface do not need to implement it.
|