阅读背景:

在实现Iterable接口时,iterator()方法不应该返回集合的克隆吗?

来源:互联网 

I have seen many examples of how to implement the Iterable interface where the iterator() method merely returns the original collection to be iterated. But this seems to defy part of the purpose of an iterator, in that one should be able to iterate over said collection without worrying about the collection changing underneath you. Shouldn't the iterator() method of an Iterable always return a clone of the collection? And, preferably, a deep clone?I have seen many examples of how to implement t




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: