无法推断功能接口类型 Java 8
我有一个工厂(注册表DP)来初始化类:
public class GenericFactory extends AbstractFactory {
public GenericPostProcessorFactory() {
factory.put("Test",
defaultSupplier(() -> new Test()));
factory.put("TestWithArgs",
defaultSupplier(() -> new TestWithArgs(2,4)));
}
}
interface Validation
Test implements Validation
TestWithArgs implements Validation
在抽象工厂
protected Supplier<Validation> defaultSupplier(Class<? extends Validation> validationClass) {
return () -> {
try {
return validationClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Unable to create instance of " + validationClass, e);
}
};
}
但我不断得到无法推断功能接口类型错误。我在这里做错了什么?