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 one returns yet another Callable<*> object! And so on. You should find out how many Callable<*> objects there are.

If the first iteration of the call() method returns a non-Callable object, your method should return 1.

Write a method that solves this problem.

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

Write a program in Kotlin
import java.util.concurrent.Callable

fun determineCallableDepth(callable: Callable<*>): Int {
// write your code here
}
___

Create a free account to access the full topic