title: java compiler error with generics and an iterator
body: <p>I have the following code (Yes, I know the iterator is implemented incorrectly.  This is an exam question I'm writing):</p>
  
  <pre><code>public class MyList&lt;Integer&gt; extends ArrayList&lt;Integer&gt; {
    public void noOdds() {
      MyIterator&lt;Integer&gt; iter = this.iterator();
      while (iter.hasNext()) { 
        if (iter.next() % 2 == 1)
          iter.remove();
      }   
    } 
  
    public MyIterator&lt;Integer&gt; iterator() {
      return new MyIterator&lt;Integer&gt;(this);
    } 
  
    public class MyIterator&lt;Integer&gt; implements Iterator&lt;Integer&gt; {
      List&lt;Integer&gt; data;
      int size;
      int position;
  
      MyIterator(List&lt;Integer&gt; data) {
        this.data = data;
        this.size = data.size();
        this.position = 0;
      } 
  
      public boolean hasNext() {
        if (this.position &lt; this.size)
          return true;
        else
          return false;
      }   
  
      public Integer next() {
        Integer tmp = this.data.get(this.position);
        this.position++;
        return tmp;
      }
  
      public void remove() {
        if (this.position == 0)
          throw new IllegalStateException("next hasn't been called yet");
        this.data.remove(this.position - 1);
      }
    }
  }
  </code></pre>
  
  <p>When I compile, it won't auto box the Integer for modulo op, and I get </p>
  
  <p>MyList.java:9: error: bad operand types for binary operator '%'
              if (iter.next() % 2 == 1)</p>
  
  <p>first type:  Integer</p>
  
  <p>second type: int</p>
  
  <p>If I change <code>iter.next()</code> to <code>iter.next().intValue()</code>, I get</p>
  
  <p>MyList.java:9: error: cannot find symbol
  if (iter.next().intValue() % 2 == 1)</p>
  
  <p>symbol:   method intValue()</p>
  
  <p>location: class Object</p>
  
  <p>However, if I change </p>
  
  <pre><code> public class MyList&lt;Integer&gt;...
  </code></pre>
  
  <p>to </p>
  
  <pre><code> public class MyList
  </code></pre>
  
  <p>then the errors go away.</p>
  
  <p>Thoughts on what's going on?</p>
  
  <p>Thanks.</p>