생성자 참조를 위한 함수형 인터페이스 생성 #47
Answered
by
Irisation23
coalong
asked this question in
CHAPTER 3 람다 표현식 - Q&A
-
p.120 퀴즈 3-7. Q.
A.
// 사용자 정의 함수형 인터페이스
public interface TriFunction<T, U, V, R> {
R apply(T t, U u, V v);
}
// 새로운 생성자 참조를 사용
TriFunction<Integer, Integer, Integer, Color> colorFactory = Color::new; 생성자 참조를 사용하기 위해서 함수형 인터페이스를 새롭게 정의해서 사용해야 할까?? |
Beta Was this translation helpful? Give feedback.
Answered by
Irisation23
Jun 26, 2023
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
coalong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
질문하신 의도를 파악해 보면은 TriFunction으로 새로운 함수형 인터페이스를 구현하는 것 이외에
자바에서 제공하는
Funciton Interface
만으로 구현할 수 없는지에 대한 질문의도로 파악하고 답변을 드려보겠습니다.먼저
Color
클래스는 아래와 같은 구조로 되어있습니다.Function
을 통해Color
클래스를 생성하는 방법은 아래와 같습니다.