Monday, August 25, 2014

Default Method in Interface - JDK 8

Default method: An interface declaration can contain method signatures, default methods, static methods and constant definitions. The only methods that have implementations are default and static methods

Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces

Best practices : Use default methods only in rare case. We have to choose default method name carefully to avoid compile time error in case of one class implementing two interfaces and both interfaces have same default method name.

Static method : Static methods are similar to default method. The only difference is that static method can not be overridden like default method by implementing class.

Functional Interface: Functional interface has exactly one abstract method. @FunctionalInterface annotation can be used to mark it as functional interface.


No comments:

Post a Comment