0
1.7kviews
Functional Interface in Java 8
1 Answer
0
8views

What is Functional Interface in Java 8?

There are many new features introduced in Java 8 e.g default and static method, Lambda expressions, Date and Time API, Functional Interface, etc.

Functional interface is an interface which contains only one abstract method. We can call Functional interface as Single Abstract Method Interface(SAM).

We can declare Object class methods in Functional Interface.

The functional interface provides target type Lambda expressions and method reference.

There are many pre-defined functional interfaces in java which is provided by java but you can create your own functional interfaces.

For example:

@FunctionalInterface//it is optional 
interface Dog
{
  void run(String s);
}

class Test impements Dog 
{
  public void run(String s)
  {
    System.out.println(s);
  }
  public static void main(String args[])
  {
    Test t = new Test();
    t.run("run fast");
  }
}
Please log in to add an answer.