What is an upper bound?

Report a typo

There is a class TestClass that has a method returning upper bounded wildcard type. But we don't know a parameter type of the return value:

class TestClass {
    ...
    public Set<? extends UNKNOWN_TYPE> someMethod() {
        //
    }
    ..
}

To obtain it, let's implement printParameterType method that accepts an instance of TestClass and the name of its method.

The method should print a full name of the return upper bound type (package + class name).

Sample Input 1:

stringMethod

Sample Output 1:

java.lang.String
Write a program in Java 17
// Do not remove imports
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.util.Set;
import java.util.Scanner;

class ListParameterInspector {
// Do not change the method
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
String methodName = scanner.next();

ListParameterInspector inspector = new ListParameterInspector();
inspector.printParameterType(new TestClass(), methodName);
}

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

Create a free account to access the full topic