title: Java Generics: function parameter for a set of generic typed objects
body: <p>I am working with javax.validation / Hibernate validation.
  To validate an annotated (e.g. @NotNull at an attribute) bean, the hibernate validator is used with the javax.validation interfaces:</p>
  
  <pre><code>Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  
  public interface Validator {
      &lt;T&gt; Set&lt;ConstraintViolation&lt;T&gt;&gt; validate(T object, Class&lt;?&gt;... groups);
  }
  
  public interface ConstraintViolation&lt;T&gt; {
      String getMessage();
      Path getPropertyPath(); 
      T getRootBean();
  }
  </code></pre>
  
  <p><strong>The goal is to write a single method, which accepts differently typed sets, like:</strong> </p>
  
  <pre><code>Set&lt;ConstraintViolation&lt;TaskList&gt;&gt; violationsTaskList = validator.validate(taskList);
  Set&lt;ConstraintViolation&lt;TaskItem&gt;&gt; violationsTaskItem = validator.validate(taskItem);
  
  public void consumeViolations(Set&lt;ConstraintViolation&lt;?&gt; violations) {
      // Do something meaningful...
      violations.getMessage();
  }
  </code></pre>
  
  <p>Using the wildcard ? is best think I came up with until now but it is rejected by the compiler with the message:</p>
  
  <pre><code>consumeViolations(....&lt;?&gt;) cannot be applied to consumeViolations(....&lt;TaskList&gt;)
  </code></pre>
  
  <p>I do not want to write this method for every type T just to call getMessage() and pass it to the next method.</p>
  
  <p>Is it possible to write such a method? I only want to access methods of the ConstraintViolation interface, which are not dependent on the type T like String getMessage().</p>