How many Callable objects are there?

Report a typo

Wow! This problem is kind of tricky. If you're ready to put your thinking cap on, brace yourself and good luck! Otherwise, you can skip it for now and return any time later

You are given a Callable object. Some say that it returns another Callable object. And that Callable returns another Callable object! And so on. You should find out how many Callable objects there are.

If the first call to the call() method does not return a Callable object, your method should return 1.

Write a method that solves this problem.

Tip:

Remember that if you cast a non-Callable object to a Callable, you will get an error doing that.
You may use instanceof operator to check whether the object is Callable or not.

Write a program in Java 17
import java.util.concurrent.*;


class FutureUtils {

public static int determineCallableDepth(Callable callable) throws Exception {
// write your code here
}

}
___

Create a free account to access the full topic