I have come across the same issue. Here are my 2 classes in a very much larger project:
package ws.daley.hollow.validation;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
@Target({ TYPE, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = PasswordMatchesValidator.class)
@Documented
public @interface PasswordMatches
{
String message() default "Passwords don't match";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
and
package ws.daley.hollow.validation;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import ws.daley.hollow.persistence.admin.model.User;
import ws.daley.hollow.web.admin.dto.UserDto;
public class PasswordMatchesValidator implements ConstraintValidator<PasswordMatches, Object>
{
@Override
public void initialize(@SuppressWarnings("unused") final PasswordMatches constraintAnnotation) {/* */}
@Override
public boolean isValid(final Object obj, final ConstraintValidatorContext context)
{
@SuppressWarnings("unchecked")
final UserDto<User> user = (UserDto<User>) obj;
return user.getPassword().equals(user.getMatchingPassword());
}
}
The following line in PasswordMatches
@Constraint(validatedBy = PasswordMatchesValidator.class)
gets the error:
Type mismatch: cannot convert from Class<PasswordMatchesValidator> to Class<? extends ConstraintValidator<?,?>>[]
The code builds fine under maven both inside and outside of STS4.
I have found a temporary (and very transient) fix for the problem. Simply copy the PasswordMatches source code to the clipboard, delete the PasswordMatches class from the project, add a new class of the same name, paste the copied code back in, save and build. The problem is now gone, but only for a while. Sometime later, apparently some random occurrence causes the exact same error to reappear in exactly the same place. The above action again fixes the problem.
I am running STS4 on Eclipse. The problem did not occur before I upgraded to JDK10 from JDK8 and from STS3 to STS4, although this may be anecdotal. I suspect the problem is in the new eclipse/STS4 or it's use of language servers.