Java8 부터 함수형 인터페이스 등장java.util.function 에서 확인 가능java.util.function에 선언되어 있는 함수형 인터페이스에는 하나같이 @FunctionalInterface 어노테이션이 붙어있는것을 확인할 수 있다
함수형 인터페이스로 사용하기 위해서는 단일 메서드를 가져야하는데, 선언을 안하거나, 두개이상의 메서드를 선언할때 컴파일시 에러를 반환해준다
선언은 다음처럼 되어있다.
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FunctionalInterface {}


Function<T, R>Supplier<T>Consumer<T>Predicate<T>
하여간 많으니 몇개만 본다면
@FunctionalInterface
public interface Function<T, R> {
R apply(T t);
}
Function 과 다르게 input이 없다. output만 존재한다.@FunctionalInterface
public interface Supplier<T> {
T get();
}
Supplier와 반대라고 생각하면 된다. input은 있지만 output은 없다.System.out.print() 같은게 있을수 있겠다.@FunctionalInterface
public interface Consumer<T> {
void accept(T t);
}
boolean을 반환한다.stream() 에서 사용하는 filter() 에서 Predicate를 사용한다@FunctionalInterface
public interface Predicate<T> {
boolean test(T t);