title: Convert from Iterator<T> to Iterator<U> where T is a subclass of U
body: <p>Given a class <code>T</code> which is a subclass of <code>U</code>, is it safe to cast <code>Iterator&lt;T&gt;</code> to <code>Iterator&lt;U&gt;</code>? And assuming that the cast be safe, are there more elegant (and warning-free) ways of doing it other than:</p>
  
  <pre><code>Iterator&lt;T&gt; it = &lt;insert your Iterator&lt;T&gt; here...&gt;;
  Iterator&lt;U&gt; it2 = (Iterator&lt;U&gt;)(Iterator&lt;? extends U&gt;)it;
  </code></pre>
  
  <p>My reasoning why the cast is not dangerous is this:</p>
  
  <ol>
  <li><code>Iterator&lt;?&gt;</code> does not support inserting elements, so there is no danger of corrupting the underlying data structure by using <code>Iterator&lt;U&gt;</code> instead of <code>Iterator&lt;T&gt;</code>;</li>
  <li><code>Consumer&lt;? super U&gt;</code> is convertible to <code>Consumer&lt;? super T&gt;</code> but not vice versa. Hence, <code>Iterator&lt;U&gt;::forEachRemaining(Consumer&lt;? super U&gt; action)</code> will accept a subset of all actions eligible for the same method in <code>Iterator&lt;T&gt;</code> and, in particular, does not introduce a way of executing actions not supported by <code>Iterator&lt;T&gt;</code>; </li>
  <li><code>Iterator&lt;U&gt;::remove()</code> is equivalent to <code>Iterator&lt;T&gt;::remove()</code>;</li>
  <li><code>Iterator&lt;U&gt;::next()</code> returns a superclass of T;</li>
  </ol>