함수형 인터페이스
실제로 많이 활용되는 함수형 인터페이스
OverView
함수형 인터페이스 예제
// 인터페이스 정의
@FunctionalInterface
interface ExamInterface<T> {
// 추상(abstract) 메소드 오직 하나
T testCall();
// 디폴트 메서드의 존재 유무는 상관 없음
defualt void printDefault() {
System.out.println("Hi Default Method");
}
// 정적 메소드의 존재 유무는 상관 없음
static void printStatic() {
System.out.println("Hi Static Method");
}
}
// 호출
ExamInterface<String> interface = () -> "Hi interface";
// 추상 메서드
String str = interface.testCall();
System.out.print(str);
// 디폴트 메서드
interface.printDefault();
// 정적 메서드
interface.printStatic();
// 출력
Hi interface
Hi Static Method
Hi Default MethodJava에서 기본으로 제공하는 함수형 인터페이스 종류

Last updated