类是原始类型。对泛型类型 Class<T> 的引用应参数化
2022-08-31 15:28:26
我有以下课程(来自一个简单的春季教程)
public class CarValidator implements Validator {
public boolean supports(Class aClass) {
return Car.class.equals(aClass);
}
public void validate(Object obj, Errors errors) {
Car car = (Car) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "model", "field.required", "Required field");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "price", "field.required", "Required field");
if( ! errors.hasFieldErrors("price")) {
if (car.getPrice().intValue() == 0) {
errors.rejectValue("price", "not_zero", "Can't be free!");
}
}
}
}
其中 Validator 类是 Spring 2.5 中的类。org.springframework.validation.Validator
支持方法显示警告(类是原始类型。对泛型类型 Class 的引用应该参数化),如果我尝试向其中添加参数,例如
public boolean supports(Class<?> aClass) ...
我收到以下错误:
The method supports(Class<?>) of type CarValidator has the same erasure as supports(Class) of type Validator but does not override it
关于这种类型的问题有很多线程,但我想得到一个完整的答案,并真正理解它,而不是“隐藏”问题!@SupressWarnings