Java 实现泛型类时无法推断类型变量
我定义了以下类:Java 实现泛型类时无法推断类型变量,java,generics,Java,Generics,我定义了以下类: public class AttributeVisitor extends SimpleAnnotationValueVisitor8<Object, Object> { public AttributeVisitor() { super(); } public AttributeVisitor(Object defaultValue) { super(defaultValue); } @
public class AttributeVisitor extends SimpleAnnotationValueVisitor8<Object, Object> {
public AttributeVisitor() {
super();
}
public AttributeVisitor(Object defaultValue) {
super(defaultValue);
}
@Override
public Object visitEnumConstant(VariableElement c, Object attribute) {
return super.visitEnumConstant(c, attribute);
}
}
公共类AttributeVisitor扩展了SimpleNotationValueVisitor 8{
公共属性设置器(){
超级();
}
公共属性设置器(对象默认值){
超级(默认值);
}
@凌驾
公共对象visitEnumConstant(VariableElement c,对象属性){
返回super.visitEnumConstant(c,属性);
}
}
我试着在下面的片段中使用它
for(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> mirrorValues: annotationMirror.getElementValues().entrySet()){
mirrorValues.getValue().accept(new AttributeVisitor());
}
for(Map.Entry。这将编译:
mirrorValues.getValue().accept(new AttributeVisitor(), null);
错误:
解决方案:
new ResponseMessage("Message", null, null)) by replacing string message
annotationMirror.getElementValues()
的类型是什么?它的映射
cannot infer type arguments for `Resource<>`
cannot infer type-variable(s) T
(argument mismatch; String cannot be converted to ResponseMessage)
where T is a type-variable:
T extends Object declared in class Resource
new ResponseMessage("Message", null, null)) by replacing string message