79342545

Date: 2025-01-09 12:17:06
Score: 0.5
Natty:
Report link

Functional Interface

  1. An interface that contains only one abstract method is known as a functional interface.
  2. Along with one abstract method, a functional interface can have multiple default methods as well as static methods.
  3. The @FunctionalInterface annotation is used to indicate a functional interface.
  4. There are 43 predefined functional interfaces in Java. Some frequently used ones are Predicate, Consumer, Supplier, Function<T, R>, etc.
  5. From [Java][1] 8 onwards, lambda expressions and method references can be used to represent functional interface references. Ex:
 @FunctionalInterface
interface Runnable
{
    void run();
}

class Race
{
    public void run()
    {
        System.out.println("Running form Race class");
    }
}

public class Test
{
    public static void main(String[] args) {
        
        //providing implementation for run method through lambda
        Runnable r1 = () -> System.out.println("Running from lambda");
        r1.run();
        
        
        //Providing implementation for run method through mehtod reference
        Runnable r2 = new Race()::run;
        r2.run();
    }
    
}


  [1]: https://www.oracle.com/java/technologies/java8.html
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @FunctionalInterface
  • Low reputation (1):
Posted by: Biplabi Biswajit Das