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>() {
@Override
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");
System.out.println(animal);//false
Recommended Posts