Function <T, R>

이승민·2022년 10월 18일
0

JAVA8

목록 보기
2/18

T 타입을 받아서 R 타입을 리턴하는 함수 인터페이스

  • R apply(T t)

  • 함수 조합용 메소드

    • andThen -> andThen 내부가 나중에 실행
    • compose -> compose 내부가 먼저 실행
    	public class Example{
    		 public static void main(String[] args) {
    
    			Function<Integer, Integer> plus10 = (i) -> i + 10;
    			Function<Integer, Integer> multiply2 = (i) -> i * 2;
    
    			System.out.println(plus10.compose(multiply2).apply(2));
          		//multiply2 실행 후 plus10 실행 결과 값: 14
                 plus10.andThen(multiply2).apply(2);
    			        //puls10 실행 후 multiply2 실행 결과 값: 24
      	}
      }
      ```![](https://velog.velcdn.com/images/lee2963/post/941ab6d7-88ad-4bcf-93d8-b66a2150197c/image.jpeg)
profile
💻 끊임없이 성장하는 백엔드 개발자 💻

0개의 댓글