2010-04-26 113 views
1

我正在使用javax.validation.Validator以及基於註釋的驗證的相關類。約束驗證

Configuration<?> configuration = Validation.byDefaultProvider().configure(); 
ValidatorFactory factory = configuration.buildValidatorFactory(); 
Validator validator = factory.getValidator(); 

Set<ConstraintViolation<ValidatableObject>> constraintViolations = validator.validate(o); 
for (ConstraintViolation<ValidatableObject> value : constraintViolations) { 
    List< Class< ? extends ConstraintValidator< ? extends Annotation,?>>> list = 
      value.getConstraintDescriptor().getConstraintValidatorClasses(); 
} 

我得到一個編譯錯誤,指出:

類型不匹配:不能從列表<類<轉換?將ConstraintValidator <捕獲#4的?,?>>>擴展到列表<類<?擴展ConstraintValidator <?擴展註釋,?>>>

我錯過了什麼?

+0

你有沒有想出解決辦法? – coder 2011-05-16 22:57:31

回答

0

如果你不介意與ConstraintValidator<?, ?>正在(即你不需要ConstraintValidator<? extends Annotation, ?>),這應該工作:

Configuration<?> configuration = Validation.byDefaultProvider().configure(); 
ValidatorFactory factory = configuration.buildValidatorFactory(); 
Validator validator = factory.getValidator(); 

Set<ConstraintViolation<ValidatableObject>> constraintViolations = validator.validate(o); 
for (ConstraintViolation<ValidatableObject> value : constraintViolations) { 
    List< Class< ? extends ConstraintValidator<?,?>>> list = 
      value.getConstraintDescriptor().getConstraintValidatorClasses(); 
}