Java 코드 샘플 - Function 인터페이스로 람다 식 만들기
코드: FuncDemo.java
import java.util.function.Function;
import java.util.function.BiFunction;
public class FuncDemo {
public static void main(String[] args) {
Function<Integer, Boolean> zero = number -> number == 0;
System.out.println("Result: " + zero.apply(1234 - 1234));
System.out.println("Result: " + zero.apply(1234));
Function<Integer, Integer> one = n -> n + 1;
System.out.println("Result: " + one.apply(1));
BiFunction<Integer, Integer, Integer> two = (x, y) -> x + y;
System.out.println("Result: " + two.apply(3, 5));
}
}
결과
Result: true
Result: false
Result: 2
Result: 8