title: Java generics: how to get a generic class's Id in a generic interface?
body: <p>I am using JDK 7. </p>
  
  <p>I have an abstract class <strong><code>BaseEntity</code></strong> which is using generics:</p>
  
  <pre><code>public class BaseEntity&lt;Id extends java.io.Serializable&gt; {
    protected Id id;
  
    public BaseEntity() {
    }
  
    public Id getId() {
      return id;
    }
    public void setId(Id id) {
      this.id = id;
    }
  
    // also has hashCode() and equals() methods to be based on id
  }
  </code></pre>
  
  <p>Now I want to create an interface whose type would be <strong><code>BaseEntity</code></strong> and I also want the <strong><code>Id</code></strong> of <strong><code>BaseEntity</code></strong> to be available in the interface. How can I do that?</p>
  
  <p>I tried this code: </p>
  
  <pre><code>public interface BaseLookup&lt;T extends BaseEntity&gt; {
     T findById(Id id);
  }
  </code></pre>
  
  <p>but I got 2 messages:</p>
  
  <ol>
  <li>1st one was on <strong><code>BaseEntity</code></strong>. The message was:</li>
  </ol>
  
  <blockquote>
    <p>Base Entity is a raw type. References to generic type <code>BaseEntity&lt;Id&gt;</code>
    should be parameterized.</p>
  </blockquote>
  
  <ol start="2">
  <li>2nd one was on <code>"Id"</code>. The error message was:</li>
  </ol>
  
  <blockquote>
    <p>Id cannot be resolved to a type.</p>
  </blockquote>
  
  <p>What I am doing wrong here? </p>