Class CompletableFutureExamples

java.lang.Object
net.jrodolfo.java_evolution.java08.CompletableFutureExamples

public class CompletableFutureExamples extends Object
Demonstrates CompletableFuture, introduced in Java 8 to make asynchronous work easier to compose.

Before Java 8, Future could represent a result that would be available later, but it did not provide a fluent way to transform that result, combine it with another future, or recover from failure. Code often had to block with get() or coordinate callbacks manually.

CompletableFuture solves that problem by treating asynchronous work as a pipeline. A program can start work with supplyAsync, transform the result with thenApply, combine independent results with thenCombine, and handle errors with exceptionally. The examples use a caller-provided Executor so tests can run deterministically without depending on timing or background thread scheduling.