【发布时间】:2022-01-19 07:53:08
【问题描述】:
以下是我正在尝试完成的示例。我正在尝试创建实现GenericRunner 的LibraryRunner。但是,我收到一个 IDE 警告,指出 LibraryRunner 没有实现 GenericRunner 接口中的方法。这是有道理的,方法签名不匹配,但是如何在仍然使用扩展GenericCalculator 的LibraryCalculator 的同时使方法签名匹配?
public class LibraryRunner implements GenericRunner {
@Override
public <T> T run(LibraryCalculator<T> calculator) {
return T;
}
}
public interface GenericRunner {
<T, A> T run(GenericCalculator<T, A> calculator);
}
public interface LibraryCalculator<T> extends GenericCalculator<T, LibraryAlgorithm> {
T calc(LibraryAlgorithm algorithm) throws LibraryException;
}
public interface GenericCalculator<T, A> {
T calc(A algorithm) throws Exception;
}
public class LibraryException extends Exception {
}
【问题讨论】: