Skip to content

Instantly share code, notes, and snippets.

@deepakmehra10

deepakmehra10/copy

Created Apr 27, 2020
Embed
What would you like to do?
CompletableFuture nameFuture = CompletableFuture.supplyAsync(() -> "Deepak");
CompletableFuture nameFutureCopy = nameFuture.copy();
CompletableFuture withSurname = nameFuture.thenApply(name -> "Deepak Mehra");
// Should be avoided, only for demonstration purpose
System.out.println(withSurname.join());
// Change in original instance should affect it's copy instance.
System.out.println(nameFutureCopy.join());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment