title: Why do i have to add a explicit casting when use a generics type with wildcard parameterized type?
body: <p>Here is the code:</p>
  
  <pre><code>public class Pair&lt;X,Y&gt; {
      private X first;
      private Y second;
      public Pair(X x, Y y) {
              first = x;
              second = y;
      }
      public X getFirst() { return first; }
      public Y getSecond() { return second; }
      public void setFirst(X x) { first = x; }
      public void setSecond(Y y) { second = y; }
  }
  
  final class Test {
      public static void main(String[] args) {
          String a = "a";
          Pair&lt;?,?&gt; pair = new Pair&lt;String,Long&gt;("limit", 10000L);
          String s = pair.getFirst();
  }
  </code></pre>
  
  <p>this code doesn't work,because the object return by the method <code>getFirst()</code>cannot be converted to string：</p>
  
  <pre><code>Test.java:5: error: incompatible types: CAP#1 cannot be converted to String
                  String s = pair.getFirst();
                                          ^
    where CAP#1 is a fresh type-variable:
      CAP#1 extends Object from capture of ?
  1 error
  </code></pre>
  
  <p>It seems that the compiler had added an implicit cast but failed.</p>
  
  <p>But when i add a  explicit cast(<code>String s = (String)pair.getFirst()</code>),  it works.</p>
  
  <p>Why does this happen ???</p>