title: Why is the generic parameter necessary in CDI?
body: <p>I use Java 1.7 and Glassfish 4.0.</p>
  
  <p>There is a generic interface <code>Service&lt;T&gt;</code> with 2 implementations where the second extends the first.</p>
  
  <pre><code>public interface Service&lt;T&gt;{
    void serve(T t);
  }
  
  @Singleton @ServiceQualifier(type=ServiceType.DEFAULT)
  public class DefaultService implements Service&lt;MyType&gt;{
    public void serve(MyType t){
      ...
    }
  }
  
  @Singleton @ServiceQualifier(type=ServiceType.SPECIAL)
  public class SpecialService extends DefaultService{
    @Override
    public void serve(MyType t){
      ...
    }
  }
  </code></pre>
  
  <p>In order to use CDI there is a qualifier annotation where <code>ServiceType</code> is a simple enum with <code>ServiceType.DEFAULT</code> and <code>ServiceType.SPECIAL</code>.</p>
  
  <pre><code>@Qualifier
  @Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
  public @interface ServiceQualifier {
    ServiceType type();
  }
  </code></pre>
  
  <p>If the Service is injected like this</p>
  
  <pre><code>@Inject @ServiceQualifier(type=ServiceType.DEFAULT)
  private Service service;
  </code></pre>
  
  <p>the CDI Container throws an exception (I deploy the app to glassfish 4 if that matters.)</p>
  
  <blockquote>
    <p>Error occurred during deployment: Exception while loading the app :
    CDI deployment failure:WELD-001408 Unsatisfied dependencies for type
    [Service] with qualifiers [@ServiceQualifier]</p>
  </blockquote>
  
  <p>But if the Service is injected with the generic parameter it works.</p>
  
  <pre><code>@Inject @ServiceQualifier(type=ServiceType.DEFAULT)
  private Service&lt;MyType&gt; service;
  </code></pre>
  
  <p>I am very confused now because i thought that <a href="https://stackoverflow.com/questions/339699/java-generics-type-erasure-when-and-what-happens?lq=1">generic parameters are removed at compile time in Java</a>. Can someone explain why it is necessary to specify the generic parameter although it is compiled away?</p>
  
  <p>Thanks in advance.</p>