Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.concurrent.CompletableFuture;
public class Main {
public static void main(String[] args) {
CompletableFuture<Integer> length = CompletableFuture.supplyAsync(() -> "learnfrenzy").thenApply(String::toUpperCase);
System.out.println(length.join());
}
}
- A toUpperCase cannot be a method reference
- B thenApply(String::toUpperCase) produces a CompletableFuture<String>, not <Integer>; use thenApply(String::length) or change the type Correct
- C supplyAsync cannot return a String
- D join returns void
Correct Answer: Option B
The function given to thenApply decides the new future's type.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!