On Thu, 2010-07-22 at 14:46, Gregg Wonderly wrote:

> > Ok, didn't think of that, still using the old for loop.
> 
> I think the subtle issue that Peter was getting at though, is that Iterator 
> has 
> the "remove()" method which perhaps should not be a published behavior, since 
> it 
> implies an API that is not currently in the design of the system.  I'm not 
> that 
> bothered by this in an internal API, but in some cases, you have to be 
> careful, 
> and perhaps pass a copy, as in
> 
>       new ArrayList<Task>( ... ).interator()
> 
> just to make sure that your original collection is not compromised by other 
> software.
> 

'remove()' is an optional operation.  You can just take the original
Iterator and wrap it inside an Iterator that delegate next()  and
hasNext() to the original, but throws UnsupportedOperationException on
everything else.

Matter of fact, I wouldn't be surprised if
java.util.Collections.unmodifiableCollection(...) does pretty much that.

> Gregg Wonderly

Cheers,

Greg.

-- 
Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.
http://stratuscom.com

Reply via email to