티스토리 뷰
4.1 함수형 인터페이스(Functional Interface)
- 단 하나의 추상 메서드만 정의된 인터페이스
- 함수를 일급시민(값)으로 취급
- 함수 자체를 파라미터로 전달 가능
@FunctionalInterface
public interface Comparator<T> {
int compare(T o1, T o2); // 단 하나의 추상 메서드
...
default Comparator<T> reversed() {
return Collections.reverseOrder(this);
}
default Comparator<T> thenComparing(Comparator<? super T> other) {
Objects.requireNonNull(other);
return (Comparator<T> & Serializable) (c1, c2) -> {
int res = compare(c1, c2);
return (res != 0) ? res : other.compare(c1, c2);
};
}
...
}
4.2 람다 표현식(Lambda Expression)
- 함수형 인터페이스를 구현한 클래스의 메서드 구현을 단순화한 표현식
4.3 메서드 레퍼런스(Method Reference)
- 람다 표현식을 더 간결하게 작성하는 방법
- ClassName :: static method 유형
- ClassName :: instance method 유형
- object :: instance method 유형
- ClassName :: new 유형
// 람다 표현식
(Car car) -> car.getCarName()
// 메서드 레퍼런스
Car::getCarName
4.4 함수 디스크립터(Function Descriptor)
- 함수형 인터페이스의 파라미터 형식과 리턴 값의 형태를 설명하는 것
'공부 > 스프링으로 시작하는 리액티브 프로그래밍' 카테고리의 다른 글
Chapter 05 | Reactor 개요 (0) | 2023.07.21 |
---|---|
Part 02 | Project Reactor (0) | 2023.07.21 |
Chapter 03 | Blocking I/O와 Non-Blocking I/O (0) | 2023.07.21 |
Chapter 02 | 리액티브 스트림즈(Reactive Streams) (0) | 2023.07.21 |
Chapter 01 | 리액티브 시스템과 리액티브 프로그래밍 (0) | 2023.07.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크