我的项目中有如下代码:
public class CommandValidator extends AbstractValidator<CommandTransaction> {
@Override
public boolean validate(CommandTransaction object) {
return false;
}
}
public abstract class AbstractValidator<T> implements Validator<T>{
@Override
public boolean validate(T object) {
return false;
}
}
public interface Validator<T> {
default boolean validate(T object) throws Exception {
return false;
}
}
当我尝试编译它时出现错误:
[ERROR] error: name clash: validate(CommandTransaction) in CommandValidator overrides a method whose erasure is the same as another method, yet neither overrides the other
[ERROR] first method: validate(Object) in Validator
[ERROR] second method: validate(T) in AbstractValidator
[ERROR] where T is a type-variable:
[ERROR] T extends Object declared in class AbstractValidator
知道是什么导致了错误吗?为什么第一种方法有 Object 而不是 generic validate(Object)
?