[Java] Functional interface

What is a functional interface?

Interface with only one abstract method (static and default methods are ignored)

◆Functio<T,R>### -Convert the value of the received argument -T = method argument type, R = method return type -The abstract method is R apply (T t)

Function<Integer,String> func = f -> f + "become";
String s =  func.apply(1);
System.out.println(s); //Become 1

◆Consumer<T> -Process using the received argument (no return value) -T = method argument type -Abstract method accept (T t)

Consumer<String> dog = e -> System.out.println("hello," + e);
dog.accept("Shiba inu");//hello,Shiba inu

If you write without using a lambda expression, it will be as follows

Consumer<String> dog = new Consumer<String>() {
	public void accept(String name) {
				System.out.println("hello," + name);//hello,Shiba inu

◆Predicate<T> -Judge with the received argument and return Boolean -T = method argument type ・ Abstract method is test (T)

Predicate<String> result = c -> {return c.equals("dog");}; 
boolean animal = result.test("cat");

Recommended Posts

[Java] Functional interface
About Java functional interface
java standard functional interface
java (interface)
[java] interface
[Java] Functional interface / lambda expression
About Java interface
Functional interface introduction
About interface, java interface
Callable Interface in Java
Functional interface review notes
JAVA learning history interface
Java learning memo (interface)
Advanced inheritance abstract, interface -java
JAVA learning history interface inheritance
Check Java9 Interface private methods
Implement functional quicksort in Java
Access the network interface in Java
Java and first-class functions-beyond functional interfaces-
[Java beginner] About abstraction and interface
Java Functional Programming Exercise Book --zipWith-
Introduction to Functional Programming (Java, Javascript)
Imitate Java's functional interface in Kotlin
[JAVA] Difference between abstract and interface
Interface Try to make Java problem TypeScript 7-3
Java learning (0)
[Java] array
Java protected
[Java] Module
Java array
Significance of interface learned from Java Collection
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
Java array
[Java] ArrayDeque
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
Understand java interface in your own way
Interface benefits
java reflexes
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array