无法通过泛型访问类方法
问题描述:
我将我的方法更改为通用方法。现在发生的是,我在反序列化 methodB
中的类,并访问它的方法,我不能再做了。
I changed my method to generic method. What is happening now is that I was deserializing the class inside the methodB
and accessing its methods which I can not do anymore.
<T> void methodB(Class<T> clazz) {
T var;
HashMap<String, T> hash = new HashMap<>();
}
void methodA () {
methodB(classA.class);
}
最初位于 methodB
没有泛型,
var = mapper.convertValue(iter.next(), ClassA.class);
var.blah() //works fine
使用泛型后,
var = mapper.convertValue(iter.next(), clazz);
var.blah() //cannot resolve the method.
如何访问 blah()
classA
?