allOf()에서 컬렉션으로 반환하는 것을 설명할 때 코드
733
11 câu hỏi đã được viết
12:03분 쯤에 완성된 코드
List<CompletableFuture<String>> futures = Arrays.asList(hello, world);
CompletableFuture<String>[] futuresArray = futures.toArray(new CompletableFuture[futures.size()]);
CompletableFuture<List<String>> results = CompletableFuture.allOf(futuresArray)
.thenApply(v -> futures.stream()
.map(CompletableFuture::join) // join()은 Unchecked Exception, get()은 Checked Exception 발생
.collect(Collectors.toList()));
results.get().forEach(System.out::println);
Completablefuture 작업들을 컬렉션으로 만들지않고, thenApply()에서 결과값을 List로 만들어주기
CompletableFuture<List<String>> results = CompletableFuture.allOf(hello, world)
.thenApply(v -> Arrays.asList(hello.join(), world.join()));
results.get().forEach(System.out::println);이 때 두 개의 코드는 동일한 기능으로 작동해도 된다고 봐도 될까요??
출력값도 동일하고, 강사님께서 말씀해주신대로 hello와 world 작업이 끝난 후에 그 결과값을 join()으로 가져와서 List로 만드는 기능으로 이해하고 있습니다.
해당 프로젝트를 똑같이 따라하려니 spring installer가 버전이 17부터 가능하네요.
0
28
1
CompletableFuture의 get 실행에 대해 궁금한 점이 있습니다
0
267
2
기본 인터페이스의 기본 제공 메서드 관련 질문 (왜 이걸 사용하는지)
0
553
2
static 과 metaspace 관련 질문있습니다.
0
737
0
Map의 가장 큰 특징이 key는 null이 아니다
0
2431
2
Optional 질문드립니다.
0
496
0
인텔리제이 콘솔창
0
598
0
Supplier를 쓰는 이유
0
1394
1
[참고] LTS주기
0
497
1
orElseThrow()
1
1123
2
findFirst함수
0
383
1
메서드 레퍼런스
1
506
1
primitive type 질문
0
333
1
FunctionalInterface 상속 관계 질문
0
318
1
함수형 인터페이스를 왜 사용하나요?
1
522
1
while문 세미콜론
0
460
1
flatMap Optional과 Stream에서의 차이점을 제가 잘 이해했는지 헷갈립니다!
0
449
1
람다식과 익명 클래스
0
352
1
steam api 예제 git 주소
3
814
1
thread.sleep질문
0
417
2
.orElse 매개변수 질문
0
280
1
isPresent( ) 와 null 질문
0
356
1
예제 코드 질문
2
306
1
코드 질문있습니다.
0
255
1

