Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is CompletableFuture.newIncompleteFuture() in Java?

abhilash

newIncompleteFuture() is an instance method of the CompletableFuture class, which is used to get a new CompletableFuture that is in an incomplete stage.

The newIncompleteFuture method is defined in the CompletableFuture class. The CompletableFuture class is defined in the java.util.concurrent package. To import the CompletableFuture class, we check the following import statement:

import java.util.concurrent.CompletableFuture;

Syntax


public <U> CompletableFuture<U> newIncompleteFuture()

Parameters

This method has no parameters.

Return value

This method returns a CompletableFuture.

Code

import java.util.concurrent.*;

public class Main {

    public static void main(String[] args){
        CompletableFuture<String> completedFuture = CompletableFuture.completedFuture("educative");
        CompletableFuture<String> incompleteFuture = completedFuture.newIncompleteFuture();
        System.out.println(incompleteFuture);
    }
}
Implementation of the "newIncompleteFuture" method

Explanation

  • Line 1: We import the relevant classes.
  • Line 6: We define a future called completedFuture, which is in a completed stage, with the value educative.
  • Line 7: We create an incomplete future called incompleteFuture, by invoking the newIncompleteFuture() method on completedFuture.
  • Line 8: We print the incompleteFuture future to the console.

RELATED TAGS

java
communitycreator
RELATED COURSES

View all Courses

Keep Exploring