부록 1. 함수형 인터페이스의 집합

Functional Programming in Java 8의 부록 1을 요약한 내용 입니다.

우리가 친숙해져야 할 인터페이스들의 집합에 대해 알아보도록 하자 여기서 살펴볼 모든 인터페이스는 java.util.function 패키지에 속해있다.

Consumer<T>

  • 추상 메서드 : accept()

  • 디폴트 메서드 : andThen()

  • 일반적인 사용법 : forEach() 메서드의 파라미터로 사용

  • 원시 타입과 함께 사용하는 경우 : IntConsumer, LongConsumer, DoubleConsumer

Supplier<T>

  • 추상 메서드 : get()

  • 디폴트 메서드 : -

  • 일반적인 사용법 : 레이지 무한(infinite) Stream을 생성하고 Optional 클래스의 orElseGet() 메서드의 파라미터로 사용

  • 원시 타입과 함께 사용하는 경우 : IntSupplier, LongSupplier, DoubleSupplier

Predicate<T>

  • 추상 메서드 : test()

  • 디폴트 메서드 : and(), negate() 그리고 or()

  • 일반적인 사용법 : filter()와 anyMatch()와 같은 Stream 메서드의 파라미터로 사용됨

  • 원시 타입과 함께 사용하는 경우 : IntPredicate, LongPredicate, DoublePredicate

Function<T,R>

  • 추상 메서드 : apply()

  • 디폴트 메서드 : andThen(), Compose()

  • 일반적인 사용법 : Stream의 Map() 메서드의 파라미터로 사용됨

  • 원시 타입과 함께 사용하는 경우 : IntFunction, LongFunction, DoubleFunction, IntToDoubleFunction, DoubleToIntFunction

Last updated