Functional interface has only one abstract method which are also called as Single Abstract Method Interfaces (SAM interfaces).
@FunctionalInterface annotation helps to create functional interface
@FunctionalInterface annotation helps to create functional interface
@FunctionalInterface public interface SampleFunctionalInterface{ public void methodName(); // Create another method will give you an error because we declared this interface as Functional interface by annotating with FunctionalInterface }
We can add default methods other than one abstract method because we have implementation for default methods.
@FunctionalInterface public interface FuntionalInterfaceExample{ public void display(); // this is an abstract method // we can add default methods , which is valid // because default methods has implementation default void method1(){ //Method body } default String method2() { // method body } }
We can override java.lang.Object class methods in Functional interface.
Comparator is a functional interface but it has two methods compare() and equals() , but here equals() is the method which will be overriden
Post a Comment
Post a Comment