title: How am I misusing generics with commons beanutils?
body: <p>I have two simple interfaces:</p>
  
  <pre><code>public interface HasId&lt;ID extends Serializable&gt; extends Serializable {
    T getId();
  }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>public interface HasLongId extends HasId&lt;Long&gt; {
    void setId(Long id);
  }
  </code></pre>
  
  <p>Now, if I have a class:</p>
  
  <pre><code>public class Person implements HasLongId {
    private Long id;
    private String name;
  
    public Long getId() {
        return this.id;
    }
  
    public void setId(Long id) {
        this.id = id;
    }
  
    public String getName() {
        return this.name;
    }
  
    public void setName(String name) {
        this.name = name;
    }
  }
  </code></pre>
  
  <p>And I instantiate a <code>person</code>, then pass it to <code>BeanUtils</code> I get strange behavior. For example sometimes setting id using BeanUtils works fine and other times, I get an exception because it can't find the "write" method for Id.  It seems that during reflection it finds a getter for a Serializable, but not a Long and it does not find a setter for the Serializable.  It does not do this consistently, so I suspect that calling person.getClass().getDeclaredMethod("id") will not always return the same Method, but I could be wrong about that.</p>
  
  <p>Anyway, this inconsistent behavior is really maddening because, for example, it will work in Eclipse, but not in Maven, or it will work for a long time and then with some unrelated change somewhere else it will stop working.</p>
  
  <p>Clearly I don't understand generics well enough to understand what is happening, but can anyone explain it to me and also explain how to work around it?</p>