-3

このコードを実行すると、これら 2 つのエラーが発生します

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);
}

}
4

1 に答える 1

2

問題は、BeanFactoryisTypeMatchメソッドの 2 番目の引数がClassではなく型 (生の型) を持っているため、 を使用して実装Class<?>できないことです。Class<?>これを変更することで修正できます:

public boolean isTypeMatch(String s, Class<?> class1)

これに:

public boolean isTypeMatch(String s, Class class1)

これにより警告が表示されますが、(コンパイラによっては)@SuppressWarnings("unchecked")または@SuppressWarnings("raw").

于 2013-07-28T05:56:10.750 に答える