title: Bounded wildcards in reference types
body: <p>I have trouble understanding following code about two <code>Predicate</code> objects. The first one uses a lower bounded wildcard, the second a upper bounded.</p>
  
  <pre class="lang-java prettyprint-override"><code>Predicate&lt;? super String&gt; p1 = s -&gt; s.startsWith("a"); // why can I call startsWith()?
  Predicate&lt;? extends String&gt; p2 = s -&gt; s.startsWith("a");
  
  p1.test("a"); // works
  p2.test("a"); // doesn't work (why?)
  </code></pre>
  
  <p>What I don't understand about <code>p1</code> is, why is it possible to call methods from the class <code>String</code>, e.g. <code>startsWith()</code>? Why can I only pass <code>String</code> objects into <code>p1.test()</code>, I expected to be able to call it for <code>Number</code> and <code>Object</code> objects as well.</p>
  
  <p>As <code>p1</code> behaves I thought <code>p2</code> would, but this isn't the case. I can't even pass a <code>String</code> object into <code>p2.test()</code>. This doesn't makes sense to me, because we expect an object which inherits from <code>String</code> (including <code>String</code>).</p>
  
  <p>I think it maybe has something to do with the fact, that we specify the reference type rather than the type of the object itself. But what type is then used for the object?</p>