top of page

Functional Interface in Java

Jonathan

A functional interface is an interface that contains only one abstract method.

These interfaces are used primarily with lambda expressions and method references.


Example of a functional interface:


@FunctionalInterface
interface MyFunctional {
	void doSomething();
}

Built-in Functional Interfaces


Java provides many built-in functional interfaces such as:

  1. Predicate

  2. Function

  3. Consumer

  4. Supplier


 
  1. Predicate

    Predicate<T>: Represents a Boolean-valued function of one argument.


  2. Function

    Function<T, R>: Represents a function that takes an argument of type T and returns a result of type R.


  3. Consumer

    Consumer<T>: Represents an operation that takes a single input argument and returns no result.


  4. Supplier

    Supplier<T>: Represents a function that supplies a result of type T without taking any arguments.


 

Key Points of Functional Interface


  • One abstract method

  • Can have multiple default or static methods

  • Can be used with lambda expressions


 








Tags:

0 views

Comments


Single post: Blog_Single_Post_Widget
bottom of page