본문 바로가기

공부/안드로이드

[Android][platform] Consumer

1. 정의

(1) Consumer

location : java.util.function.interfaces

Represents an operation that accepts a single input argument and returns no result. Unlike most other functional interfaces, Consumer is expected to operate via side-effects.

This is a functional interface whose functional method is accept(java.lang.Object).

  • 단일 입력변수(argument)를 받아서 아무런 반환값을 내놓지 않는 연산을 나타낸다. 대부분의 다른 '기능적 인터페이스'와는 달리, Consumer는 Side-effect를 통하여 무언가의 동작을 한다.
  • 'accept' 함수를 가지는 인터페이스이다.

*side-effect : 지역 환경 밖에서 '상태 변수'가 수정되는 상황

 

(2) Stream.Builder

location : java.util.steam.Interfaces

A mutable builder for a Stream. This allows the creation of a Stream by generating elements individually and adding them to the Builder (without the copying overhead that comes from using an ArrayList as a temporary buffer.)

A stream builder has a lifecycle, which starts in a building phase, during which elements can be added, and then transitions to a built phase, after which elements may not be added. The built phase begins when the build() method is called, which creates an ordered Streamwhose elements are the elements that were added to the stream builder, in the order they were added.
  • Stream을 위한 mutable 빌더 = 이렇게하면 요소를 개별적으로 생성하고 빌더에 추가하여 Stream을 만들 수 있습니다.(임시 버퍼로서 따로 배열을 만들어서 복사하는 오버헤드없이 가능해짐.)
  • 스트림 빌더에는 Building 단계가 시작될 때 라이프 사이클을 가진다. : 요소가 추가되고, built 단계로 전환, 요소가 추가되지 않는 그 이후의 단계를 가진다.  Built 단계는 build() 함수 콜때 시작되는데, 스트림 빌더에 추가 된 요소가 순서대로 추가 된 순서화 된 스트림을 작성한다.