title: Using Jscience to compute price for n units provided unit price and quantity
body: <p>I am looking for a better way to compute using Jscience but the generic pattern is much tougher to get a clear solution. I need to compute price for n units provided the unit price for a unit quantity is defined. like,</p>
  
  <pre><code>    Measure&lt;Double, ? extends Quantity&gt; unitQuantity = Measure.valueOf(1.0,
              Unit.valueOf("kg"));
      Amount&lt;Money&gt; unitPrice = Amount.valueOf(150.0, USD);
      Measure&lt;Double, ? extends Quantity&gt; quantity = Measure.valueOf(500.0,
              MILLI(Unit.valueOf("kg")));
      Amount&lt;Money&gt; amount = unitPrice.times(quantity.to(unitQuantity.getUnit())
                         .getValue() / unitQuantity.getValue());
  </code></pre>
  
  <p>For the above code I am getting this error:</p>
  
  <pre><code>The method to(Unit&lt;capture#7-of ? extends Quantity&gt;) in the type 
  Measure&lt;Double,capture#7-of ? extends Quantity&gt; is not applicable for 
  the arguments (Unit&lt;capture#8-of ? extends Quantity&gt;)
  </code></pre>
  
  <p>I read about generics at <a href="http://docs.oracle.com/javase/tutorial/extra/generics/morefun.html" rel="nofollow">Java Tutorials</a> and tried the following, but still no clear solution:</p>
  
  <pre><code>    Amount&lt;Money&gt; amount = compute(unitPrice,unitQuantity,quantity)
  
      private &lt;T extends Quantity&gt; Amount&lt;Money&gt; compute(Amount&lt;Money&gt; unitPrice,
          Measure&lt;Double, T&gt; unitQuantity, Measure&lt;Double, T&gt; quantity) {
      return unitPrice.times(quantity.to(unitQuantity.getUnit()).getValue()
              / unitQuantity.getValue());
  }
  </code></pre>
  
  <p>Now getting this error: </p>
  
  <pre><code>   The method compute(Amount&lt;Money&gt;, Measure&lt;Double,T&gt;, Measure&lt;Double,T&gt;) 
     in the type JscienceEx is not applicable for the arguments (Amount&lt;Money&gt;, 
     Measure&lt;Double,capture#7-of ? extends Quantity&gt;, Measure&lt;Double,capture#8-of ?    
     extends Quantity&gt;)
  </code></pre>