title: java operator + not defined for type(s) Integer, int
body: <p>I am trying to implement a shopping cart and I have some problems with the Integer class. This is the code:</p>
  
  <pre><code>public class ShoppingCart&lt;Product, Integer&gt; extends TreeMap&lt;Product, Integer&gt; {
  
  void addToCart(Product product) {
      if (this.containsKey(product)) {
          Integer nrOfProds = this.get(product);
          this.put(product, nrOfProds + 1); //the problem is here
      } else
          this.put(product, Integer.valueOf(1)); //and also here
  }
  ....
  }
  </code></pre>
  
  <p>Eclipse says "operator + undefined for type(s) Integer, int". But I read about unboxing, and I thought I would be ok.</p>
  
  <p>Never mind, I tried to work this around, so I tried calling intValue() on nrOfProds. This time, Eclipse said "method intValue() is undefined for type Integer". How come? It is defined for type Integer.</p>
  
  <p>There<code>s also a problem with with Integer.valueOf(1). It</code>s undefined method, again.</p>
  
  <p>What is wrong with this? </p>