The getNumberOfDependents
method is an instance method that is defined in the CompletableFuture
class. The CompletableFuture
class is defined in the java.util.concurrent
package. This method is used to return the number of CompleteFutures
that are dependent on the completion of the current CompleteFuture
.
To import the CompletableFuture
class, we check the following import statement:
import java.util.concurrent.CompletableFuture;
public int getNumberOfDependents()
This method has no parameters.
This method returns the number of dependent CompletableFutures
.
import java.util.concurrent.*; public class Main { public static void main(String[] args) { CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); completableFuture.thenApply(i -> i + 1); completableFuture.thenApply(i -> i - 1); System.out.println("Number of dependents - " + completableFuture.getNumberOfDependents()); completableFuture.thenApply(i -> i + 2); System.out.println("Number of dependents - " + completableFuture.getNumberOfDependents()); } }
CompletableFuture
object called completableFuture
.thenApply
method.completableFuture
future.thenApply
method.completableFuture
future.RELATED TAGS
CONTRIBUTOR
View all Courses