我有以下课程(来自简单的Spring教程)
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!");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Validator类是org.springframework.validation.Validator
Spring 2.5中的类.
support方法显示一个警告(Class是一个原始类型.对泛型类的引用应该参数化),如果我尝试添加参数,如
public boolean supports(Class<?> aClass) ...
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
The method supports(Class<?>) of type CarValidator has the same erasure as supports(Class) of type …