Skip to content

Instantly share code, notes, and snippets.

@deepakmehra10
Created April 27, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakmehra10/b243f24268fad8504101e40077052c83 to your computer and use it in GitHub Desktop.
Save deepakmehra10/b243f24268fad8504101e40077052c83 to your computer and use it in GitHub Desktop.
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