About Java functional interface

What is a functional interface?

An interface that has only one abstract method and can be an assignment destination for passing lambda expressions and method references.

Functional interface conditions

**-Can have only one abstract method -Abstract methods that are public methods of Object class are not included -It is possible to have multiple default methods and static methods **

The definition of the functional interface is written as follows.


public interface Sample {
    public abstract void Hello(String name);

Annotating ** @ FunctionalInterface ** makes it clear that it is a functional interface, which allows you to issue a compile error if the interface does not meet the requirements of a functional interface.


The java.util.function package provides several types of functional interfaces. It can be roughly divided into 4 types according to the argument to be received and the pattern of the result to be returned. The basic functional interface is as follows:

type Abstract method What you can do
Supplier T get() Returns a T-type return value with no arguments
Consumer void accept(T t) Returns processing (no value is returned).
Function<T, R> R apply(T t) Takes T as an argument and returns R as a result
Predicate boolean test(T t) Takes a T-type argument and returns a boolean value as a result

In addition, there are other types such as an interface when there are two arguments, so use them properly according to the purpose.

Recommended Posts

About Java functional interface
About Java interface
[Java] About interface
[Java] Functional interface
About interface, java interface
java standard functional interface
[Java] Functional interface / lambda expression
java (interface)
[java] interface
[Java beginner] About abstraction and interface
[Java] About Java 12 features
[Java] About arrays
Functional interface introduction
Something about java
Where about java
About Java features
About Java threads
About Java class
About Java arrays
About java inheritance
About List [Java]
About java var
About Java literals
About Java commands
Java, about 2D arrays
About class division (Java)
Commentary: About the interface
About [Java] [StreamAPI] allMatch ()
About Java StringBuilder class
Callable Interface in Java
Functional interface review notes
[Java] About Singleton Class
About Java method binding
[Java] About anonymous classes
About method splitting (Java)
[Java Silver] About initialization
JAVA learning history interface
About Java Array List
About Java Polymorphism super ()
About inheritance (Java Silver)
About Java String class
About Java access modifiers
About Java lambda expressions
About Java entry points
About Java 10 Docker support
Personal summary about Java
[Java] About enum type
Java learning memo (interface)
All about Java programming
About java abstract class
A note about Java GC
Advanced inheritance abstract, interface -java
What I researched about Java 8
About an instance of java
JAVA learning history interface inheritance
What I researched about Java 6
[Gradle] About Java plug-in tasks
Try functional type in Java! ①
About Java variable declaration statements
What I researched about Java 9
[Java] About try-catch exception handling