Let's say I have a class and method like this:
public class Example {
private final Map<String, Object> stuff = new HashMap<>();
public <T> T getValue(String key) {
return (T) stuff.get(key);
}
}
Is it possible to force someone writing code that calls getValue()
to explicitly provide a type witness to the method call?
Example example = new Example();
Boolean resultWithParameter = example.<Boolean>getValue("some_key");
What I'd like to do is always require the parameter when calling the method. Is there a way to do that? I know I could always add a Class
parameter but I was exploring other options.