title: Java: Generic methods and numbers
body: <p>I want to make a generic method which makes the total sum of a <code>List</code> of numbers.</p>
  
  <p>What I was trying is this:</p>
  
  <pre><code>public static &lt;T extends Number&gt; T sumList(List&lt;T&gt; data)
  {
      T total = 0;
      for (T elem : data)
      {
          total += elem;
      }
      return total;
  }
  </code></pre>
  
  <p>But the problem is that <code>there is no += operator in T</code> and that <code>total can't be assigned to zero</code>.</p>
  
  <p>How can I do this?</p>
  
  <p>Thanks</p>