• Post Reply Bookmark Topic Watch Topic
  • New Topic

Danger of Iterator?  RSS feed

Sveta Zvereva
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!