• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Danger of Iterator?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am wondering about safety of Iterator.remove() method. Lately I was told that since this is an "optional" operation, it is unsafe to use it if the collection on which this iterator is used is passed as a parameter of type List to a method. I understand that if user decides to create their own implementation of List, they will have to implement a bunch of methods including MyList.Iterator() and provide implementation for Iterator itself. This in turn means implementation of all basic Iterator functionality.
But I still dont see any increased danger of remove() operation. Am I missing something here? why optional operation is more dangerous then non-optional? After all user still may choose not to implement even mandatory methods and provide some dummy implementation.

Thank you!
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic