How many type variables defined?

Report a typo

Here is a class TestClass that has a method with declared type variables:

class TestClass {
    ...
    public <A, B, C, ...> void someMethod() {
        //
    }
    ..
}

Implement printTypeVariablesCount method that accepts an instance of TestClass and the name of its method.

The method should print the number of type variables.

Sample Input 1:

<T> void singleTypeMethod

Sample Output 1:

1

Sample Input 2:

<K, V> void twoTypesMethod

Sample Output 2:

2
Write a program in Java 17
// Do not remove imports
import java.util.Scanner;

class TypeVariablesInspector {
public void printTypeVariablesCount(TestClass obj, String methodName) throws Exception {
// Add implementation here
}
}
___

Create a free account to access the full topic