执行此代码时出现这两个错误
error: SpringBeanFactoryPluginImpl is not abstract and does not override abstract method isTypeMatch(String,Class) in BeanFactory public class SpringBeanFactoryPluginImpl implements SpringBeanFactoryPlugin
error: name clash: isTypeMatch(String,Class<?>) in SpringBeanFactoryPluginImpl and isTypeMatch(String,Class) in BeanFactory have the same erasure, yet neither overrides the other public boolean isTypeMatch(String s, Class<?> class1)
public class SpringBeanFactoryPluginImpl implements SpringBeanFactoryPlugin,
BeanFactory {
private static BeanFactory beanFactory = new XmlWebApplicationContext();
public boolean containsBean(String s) {
// TODO Auto-generated method stub
return beanFactory.containsBean(s);
}
public String[] getAliases(String s) {
// TODO Auto-generated method stub
return beanFactory.getAliases(s);
}
public Object getBean(String s) throws BeansException {
return beanFactory.getBean(s);
}
private void checkBeanFactory(String string) throws FatalBeanException {
try {
Class clazz = Class.forName(string);
} catch (ClassNotFoundException e) {
throw new FatalBeanException(string + " was not found.");
}
}
public Object getBean(String s, Object[] aobj) throws BeansException {
// TODO Auto-generated method stub
return beanFactory.getBean(s, aobj);
}
public Class getType(String s) throws NoSuchBeanDefinitionException {
// TODO Auto-generated method stub
return beanFactory.getType(s);
}
public boolean isPrototype(String s) throws NoSuchBeanDefinitionException {
// TODO Auto-generated method stub
return beanFactory.isPrototype(s);
}
public boolean isSingleton(String s) throws NoSuchBeanDefinitionException {
// TODO Auto-generated method stub
return beanFactory.isSingleton(s);
}
public <T> T getBean(String s, Class<T> class1) throws BeansException {
return beanFactory.getBean(s, class1);
}
public boolean isTypeMatch(String s, Class<?> class1)
throws NoSuchBeanDefinitionException {
return beanFactory.isTypeMatch(s, class1);
}
public <T> T getBean(Class<T> s) throws BeansException {
return beanFactory.getBean(s);
}
}
答案 0 :(得分:2)
问题是BeanFactory
的{{1}}方法的第二个参数的类型为isTypeMatch
(原始类型),而不是Class
,因此您无法使用{ {1}}实施它。你可以通过更改它来修复它:
Class<?>
到此:
Class<?>
这会给您一个警告,您可以通过添加(取决于您的编译器)public boolean isTypeMatch(String s, Class<?> class1)
或public boolean isTypeMatch(String s, Class class1)
来抑制。