I have the following code:
UniqueConstraintViolation violation = new UniqueConstraintViolationImpl();
Set<? extends javax.validation.ConstraintViolation> violations = new HashSet<UniqueConstraintViolation>();
violations.add(violation);
throw new javax.validation.ConstraintViolationException(violations);
where UniqueConstraintViolation is interface extended javax.validation.ConstraintViolation and UniqueConstraintViolationImpl is class implemented UniqueConstraintViolation
While compiling I get following error
java:42: error: no suitable method found for add(UniqueConstraintViolation) violations.add(violation); ^ method Collection.add(CAP#1) is not applicable (argument mismatch; UniqueConstraintViolation cannot be converted to CAP#1 ) method Set.add(CAP#1) is not applicable (argument mismatch; UniqueConstraintViolation cannot be converted to CAP#1 ) where CAP#1 is a fresh type-variable: CAP#1 extends ConstraintViolation from capture of ? extends ConstraintViolation C:\workspace\zcts-travel\crud-rest\src\main\java\ru\zcts\crud\AbstractResource.java:43: error: incompatible types: Set cannot be converted to Set> throw new javax.validation.ConstraintViolationException(violations);
^ where CAP#1 is a fresh type-variable: CAP#1 extends ConstraintViolation from capture of ? extends ConstraintViolation
I just want to pass in javax.validation.ConstraintViolationException constructor the Set with my own implementation of javax.validation.ConstraintViolation. How I can do it?