问题描述
public interface IFacade<T> {public Map<String, Object> execute(T param);}public final class FacadeFactory {public static <T extends IFacade<?>> T getInstance(Class<? extends IFacade<?>> clazz) {return Factory.getBean(clazz.getSimpleName());}}public class Facade<E extends AbstractDto> implements IFacade<Map<String, Object>> {@Overridepublic Map<String, Object> execute(Map<String, Object> o) { return null; }private static <E extends AbstractDto> void doSomething(List<E> records) { }}Facade facade = FacadeFactory.getInstance(Facade.class);最前边这个Facade类原来不带<E extends AbstractDto>这个泛型,只是实现了IFacade<Map<String, Object>>这个接口。FacadeFactory.getInstance(Facade.class);这个调用也是木有问题的。现在我由于需要Facade类增加了<E extends AbstractDto>后,FacadeFactory.getInstance(Facade.class);这个工厂调用的getInstance部分就提示编译错误了。提示:ZkiFacadeFactory 的方法 getInstance(Class<? extends IFacade<?>>) 的参数 (Class<Facade>) 不匹配。请问是哪里的问题?
解决方案
维数不匹配,建议删掉T getInstance(Class<? extends IFacade<?>> clazz) 里面的IFacade<?>问号,T getInstance(Class<? extends IFacade> clazz)
解决方案二:
Facade facade = FacadeFactory.getInstance(Facade.class); 改为Facade facade = FacadeFactory.getInstance((Class<? extends IFacade<?>>) Facade.class);因为Facade是<E extends AbstractDto>,而参数需要的类型为Class<? extends IFacade<?>>