title: Why can't I use wildcard with methods receiving a parameterized argument?
body: <p>For example, I use a method <code>Measure.doubleValue(Unit&lt;?&gt; unit)</code> which returns the <code>double</code> value of a measurement, expressed in the specified <code>Unit</code>. If I pass a <code>Unit&lt;?&gt;</code> variable to it, I get the still very cryptic (to me) error message: </p>
  
  <blockquote>
    <p><code>The method
    doubleValue(Unit&lt;capture#27-of ?&gt;) in
    the type Measurable&lt;capture#27-of ?&gt;
    is not applicable for the arguments
    (Unit&lt;capture#28-of ?&gt;)</code></p>
  </blockquote>
  
  <p>I would appreciate if someone could explain what that <code>#27-of ?</code> (or any other number) means, and if there is an elegant way to get rid of this. Thus far, I remove the <code>&lt;?&gt;</code> and set the calling method <code>@SuppressWarnings("unchecked")</code> (so I pass an unchecked <code>Unit</code> instead of a <code>Unit&lt;?&gt;</code>) and everything works as desired, but I'm just curious about this, and I feel like suppressing warnings is not a good practice (isn't it a little like empty catch blocks?).</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit: Adding some code.</strong></p>
  
  <p>(I'm sorry, this is quite long, but it explains in details what I'm stuck on.)</p>
  
  <p>I am using <a href="http://jsr-275.kenai.com/apidocs/" rel="nofollow noreferrer">JSR-275</a> <a href="http://download.java.net/maven/2/javax/measure/jsr-275/0.9.4/" rel="nofollow noreferrer">version 0.9.4</a> (most recent).</p>
  
  <p>So... If I write this (very dumb example):</p>
  
  <pre><code>Measure measure = Measure.valueOf("3 m");
  measure = Measure.valueOf(measure.doubleValue(Unit.valueOf("km")), Unit.valueOf("km"));
  System.out.println(measure);
  </code></pre>
  
  <p>It works and prints "0.0030 km". But I get warning "<em>Measure is a raw type. References to generic type Measure&lt;Q> should be parameterized</em>" over the first <code>Measure</code> occurrence and warning "<em>Type safety: The method doubleValue(Unit) belongs to the raw type Measurable. References to generic type Measurable&lt;Q> should be parameterized</em>" over <code>measure.doubleValue(Unit.valueOf("km"))</code>.</p>
  
  <p>Seeing these warnings, I thought I could adjust this way (first line only):</p>
  
  <pre><code>Measure&lt;Length&gt; measure = Measure.valueOf("3 m");
  </code></pre>
  
  <p>And then I get error message on right part of assignation "<em>Type mismatch: cannot convert from Measure&lt;capture#1-of ?> to Measure&lt;Length></em>". It (Eclipse) offers me to cast the right part to <code>(Measure&amp;lt;Length&gt;)</code>. But then I get warning message over the right part "<em>Type safety: Unchecked cast from Measure&lt;capture#1-of ?> to Measure&lt;Length></em>". Fix suggested: <code>@SuppressWarnings</code> which I would prefer to avoid (for paranoid reasons I guess).</p>
  
  <p>So, I step back to <code>Measure measure = Measure.valueOf("3 m");</code> and try to give wildcard to <code>Measure</code>, as obviously, it doesn't know what "3 m" means at this moment. It could be a <code>Length</code>, but also a <code>Mass</code> or a <code>Time</code>. So I get:</p>
  
  <pre><code>Measure&lt;?&gt; measure = Measure.valueOf("3 m");
  </code></pre>
  
  <p>And no warning or error on this line; fantastic. But, on the second line:</p>
  
  <pre><code>measure = Measure.valueOf(measure.doubleValue(Unit.valueOf("km")), Unit.valueOf("km"));
  </code></pre>
  
  <p>I get and error message for <code>doubleValue</code>: "<em>The method doubleValue(Unit&lt;capture#3-of ?>) in the type Measurable&lt;capture#3-of ?> is not applicable for the arguments (Unit&lt;capture#4-of ?>)</em>". It suggests to cast <code>Unit.valueOf("km")</code> as a <code>(Unit&lt;?&gt;)</code>. Fine. Now I get error message at the exact same location: "<em>The method doubleValue(Unit&lt;capture#3-of ?>) in the type Measurable&lt;capture#3-of ?> is not applicable for the arguments (Unit&lt;capture#5-of ?>)</em>". Notice that the numbers have changed, so that's not the exact same parameters, but a similar reason. Then it does the exact same suggestion which leads to no change whatsoever in the code, since it has already been done.</p>
  
  <p>So that's what is bugging me. The only way to get it working seems to <code>@SuppressWarnings</code> or just ignore them. Isn't it strange?</p>