Hi,
I am required to create a new Collection (i.e. implements Collection interface) class, and as such I need to provide an iterator() method. This is no problem, I merely created an inner adaptor class to provide this functionality. However, most (maybe all) of the API Collection-class iterators are "fail-fast"... an iterator instance will throw a ConcurrentModificationException if any modification is made to the underlying collection outside of the iterator-instance's own remove() method. I've devised a means to accomplish this, but I was curious as to whether or not there is an "accepted way". My collection keeps track of all iterators open against it, and if a particular subset of iterators must "fail-fast", the collection sets flags within the instances to record this. The iterators, prior to performing any activity, check the value of this flag and throw exceptions accordingly.
This seems inefficient, totally prone to error, and perhaps not "the best way". Is there a "best way" and - if so - what is it?
Thank you!
dora
I am required to create a new Collection (i.e. implements Collection interface) class, and as such I need to provide an iterator() method. This is no problem, I merely created an inner adaptor class to provide this functionality. However, most (maybe all) of the API Collection-class iterators are "fail-fast"... an iterator instance will throw a ConcurrentModificationException if any modification is made to the underlying collection outside of the iterator-instance's own remove() method. I've devised a means to accomplish this, but I was curious as to whether or not there is an "accepted way". My collection keeps track of all iterators open against it, and if a particular subset of iterators must "fail-fast", the collection sets flags within the instances to record this. The iterators, prior to performing any activity, check the value of this flag and throw exceptions accordingly.
This seems inefficient, totally prone to error, and perhaps not "the best way". Is there a "best way" and - if so - what is it?
Thank you!
dora