title: Java generics + static factory methods = [panic]
body: <p>I thought, I would understand Java generics by now. But now I'm helpless again.</p>
  
  <p>I have a generic class where a c-tor constructs correctly-typed instance, while a static factory method produces a type mismatch.</p>
  
  <p>Please look at the following code:</p>
  
  <pre><code>public class _GenericFactoryMethods {
  
    public final static class DemoClass&lt;T1, T2&gt; {
      private final T1 _1;
      private final T2 _2;
  
      // static factory method
      public static &lt;T1, T2&gt; DemoClass&lt;T1, T2&gt; create(T1 _1, T2 _2) {
        return new DemoClass&lt;T1, T2&gt;(_1, _2);
      }
  
      // usual c-tor
      public DemoClass(T1 _1, T2 _2) {
        this._1 = _1;
        this._2 = _2;
      }
  
      public T1 get1() { return _1; }
  
      public T2 get2() { return _2; }
    }
  
    public void doSomething() {
      String str = "test";
  
      Class&lt;? extends CharSequence&gt; _1 = str.getClass();
      CharSequence _2 = str;
  
      // works
      DemoClass&lt;Class&lt;? extends CharSequence&gt;, CharSequence&gt; dc1 =
          new DemoClass&lt;Class&lt;? extends CharSequence&gt;, CharSequence&gt;(_1, _2);
  
      // compile error
      DemoClass&lt;Class&lt;? extends CharSequence&gt;, CharSequence&gt; dc2 =
          DemoClass.create(_1, _2);
    }
  
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Uncompilable source code - incompatible types
  required: _GenericFactoryMethods.DemoClass&lt;java.lang.Class&lt;? extends java.lang.CharSequence&gt;,java.lang.CharSequence&gt;
  found:    _GenericFactoryMethods.DemoClass&lt;java.lang.Class&lt;capture#794 of ? extends java.lang.CharSequence&gt;,java.lang.CharSequence&gt;
  </code></pre>
  
  <p>Please help to understand and to solve this.<br>
  <em>(I really need static factory methods for some of such classes).</em></p>
  
  <p><strong>EDIT</strong><br>
  Can someone also <strong>explain why</strong> explicit type parameters must be used?</p>