title: Is there any way to specify Generic type based on Annotation type?
body: <p>I have a use case where I will be adding different Functional Interfaces in a list. I want to use generics with this list such that I could add only the implementations for interfaces that are explicitly annotated as <code>FunctionInterface</code>. I tried something like below:-</p>
  
  <pre><code>class GenericsInJavaAnnotations {
  
      public static void main(String[] args) {
  
          Function&lt;Product, Info&gt; function = (Product p) -&gt; p.getInfo();
          Supplier&lt;String&gt; supplier = () -&gt; "test";
          List&lt;? super FunctionalInterface&gt; functions = new ArrayList&lt;&gt;();
          functions.add(function);
          functions.add(supplier);
      }
  }
  
  class Product {
      private Info info = new Info();
  
      public Info getInfo() {
          return info;
      }
  }
  
  class Info {
  
  }
  </code></pre>
  
  <p>Using  <code>List&lt;? super FunctionalInterface&gt;</code>  as well as  <code>List&lt;? extends FunctionalInterface&gt;</code>  gives error.</p>
  
  <pre><code>Error:(15, 18) java: no suitable method found for add(java.util.function.Function&lt;java8.Product,java8.Info&gt;)
      method java.util.Collection.add(capture#1 of ? super java.lang.FunctionalInterface) is not applicable
        (argument mismatch; java.util.function.Function&lt;java8.Product,java8.Info&gt; cannot be converted to capture#1 of ? super java.lang.FunctionalInterface)
      method java.util.List.add(capture#1 of ? super java.lang.FunctionalInterface) is not applicable
        (argument mismatch; java.util.function.Function&lt;java8.Product,java8.Info&gt; cannot be converted to capture#1 of ? super java.lang.FunctionalInterface)
  Error:(16, 18) java: no suitable method found for add(java.util.function.Supplier&lt;java.lang.String&gt;)
      method java.util.Collection.add(capture#2 of ? super java.lang.FunctionalInterface) is not applicable
        (argument mismatch; java.util.function.Supplier&lt;java.lang.String&gt; cannot be converted to capture#2 of ? super java.lang.FunctionalInterface)
      method java.util.List.add(capture#2 of ? super java.lang.FunctionalInterface) is not applicable
        (argument mismatch; java.util.function.Supplier&lt;java.lang.String&gt; cannot be converted to capture#2 of ? super java.lang.FunctionalInterface)
  </code></pre>
  
  <p>I know generics well and agree that super and extends have different meaning and none covers classes or interfaces marked by an annotation.</p>
  
  <p>Do someone know any workaround or actual solution for it? Or it's a possible feature that we should expect in future versions of java?</p>