Getting rid of java.util.Iterator
<p>My problem is related to Java.  I don't like the <code>java.util</code> package because of the optional methods.  For instance, I don't like it that, when I return a <code>List</code>, I have to prevent the user to modify the list; I would like to return a list that implements, say, interface <code>UnmodifiableList</code> (yes, I know about <code>Collections.unmodifiableList()</code>, but for many reasons, I don't like to encapsulate my list).  On the other hand, when I am given a list from an external piece of code, this list could be a1) unmodifiable, a2) modifiable with side-effects on the object that returned me the list, or a3) modifiable without side-effects, and b1) immutable (assuming the elements in the list are immutable as well) or b2) mutable and unsafe to use as a key.  </p>

<p>I can rewrite most existing classes (just copy/paste the <code>java.util</code> package) and introduce interfaces <code>UnmodifiableList</code>, <code>ModifiableList</code>, etc. without much effort.  However, I have the following problem: I really like the forall mechanism </p>

<pre><code>for (final Object o: listOfObjects) {
  // do something
}
</code></pre>

<p>which uses class <code>java.lang.Iterable</code>, which uses <code>java.util.Iterator</code>.</p>

<p>So my problem is, how should I cope with the <code>Iterator</code> class?</p>

<p>I have several possible solutions but I am looking for the most elegant. </p>

<ol>
<li>Is it possible to make java use a different class than <code>Iterable</code> for the forall loops?</li>
<li>If not, is it possible to mark <code>java.util.Iterator.remove()</code> as deprecated?</li>
<li>Also, is it possible to customise my IDEs (eclipse and netbeans) so that they warn me every time I use <code>Iterator</code>?</li>
</ol>

<p>My current plan is to define my own <code>Iterator</code>, as an extension of <code>java.util.Iterator</code>, and to mark the <code>remove()</code> method as deprecated.  Next, I will have some script looking at my code and making sure that <code>java.util</code> is used nowhere (except in the definition of my own <code>Iterator</code>).  That way, I should be safe.</p>

<p>Edit: Thanks for your advises and links, guys.  Cheers.  </p>
