title: Lists with Java Annotations
body: <p>I want to validate my arguments with Java Annotation. I don't know how to use write a own Annotation for Lists. </p>
  
  <p>Here an simple example:</p>
  
  <pre><code>class test{
  
      @myAnnotation
      List&lt;myObject&gt; myElements =new List&lt;&gt;(); // validated List
  }
  
  class myObject{
  
          String name;
   }
  </code></pre>
  
  <p>my Annotation Interface:</p>
  
  <pre><code>  @Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD}) 
    @Retention(RetentionPolicy.RUNTIME)
    @Constraint(validatedBy=myAnnotation_Validator.class)
    @Documented
  
  
  public @interface myAnnotation {
            String message() default "List is not valid";
            Class &lt;?&gt;[] groups() default {};
            Class &lt;?extends Payload&gt;[] payload() default{};
  
            String[] namen();
      }
  
  public class myAnnotation_Validator implements ConstraintValidator&lt;myAnnotation, Collection&gt; {
  
      @Override
      public void initialize(Kredite_List_Check a) {
          // What to do here???
      }
  
  
      @Override
      public boolean isValid(Collection t, ConstraintValidatorContext cvc) {
          // What to do here???
          // How could i get the names from my List "myElements" ?
          return false;
      }
  
  }
  </code></pre>
  
  <p>In this Example my List is valid, if each element from my List has another name. I don't know how I get the  listobject in my Validator class and the names of myObject-elements. </p>
  
  <p>UPDATE:</p>
  
  <p>I try to describe my question in another way:</p>
  
  <p>my list is not valid if two elements from type "myObject" in my list ("myElements") have the same name!</p>
  
  <p>How could I realize this with Annotations?</p>