如何构造ConstraintViolationException?

我对javax.validation API感到困惑。 我正在写一个简单的测试来理解它:

Sample sample = new Sample(); Set<ConstraintViolation> violations = validator.validate(sample); if (!violations.isEmpty()) { // Eclipse refuses to let me use my violations variable throw new ConstraintViolationException(violations); } 

我应该如何声明违规集,以便在exception构造函数中使用它?

你可以像这样解决这个问题:

 throw new ConstraintViolationException( new HashSet>(violations)); 

您可能有兴趣跟踪解决此问题的BVAL-198 。

Interesting Posts