문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 | 다음 판 양쪽 다음 판 | ||
java:8:stream [2019/10/24 10:47] kwon37xi [unmodifiable, immutable collection] |
java:8:stream [2019/10/24 10:58] kwon37xi [unmodifiable, immutable collection] |
||
---|---|---|---|
줄 83: | 줄 83: | ||
.boxed() | .boxed() | ||
.collect(ImmutableList.toImmutableList()); | .collect(ImmutableList.toImmutableList()); | ||
+ | </ | ||
+ | |||
+ | <code java> | ||
+ | // Generic Immutable Collection collector 만들기. 컬렉션 구현체를 원하는대로 선택 | ||
+ | public static <T, A extends List< | ||
+ | Supplier< | ||
+ | | ||
+ | return Collector.of( | ||
+ | supplier, | ||
+ | List::add, (left, right) -> { | ||
+ | left.addAll(right); | ||
+ | return left; | ||
+ | }, Collections:: | ||
+ | } | ||
+ | |||
+ | // 사용예 - LinkedList 구현을 unmodifiable로 감싸기 | ||
+ | List< | ||
+ | List< | ||
+ | .collect(MyImmutableListCollector.toImmutableList(LinkedList:: | ||
</ | </ | ||
===== 참고 ===== | ===== 참고 ===== | ||
* [[https:// | * [[https:// | ||