not to keep references to the objects from this iterator ?

clipboard.png

Be careful not to keep references to the objects from this iterator.
To improve GC performance the same object is re-used in next().

请问这段注释是什么含义?

阅读 2.5k
1 个回答

下面的理解对吗?

不要保存迭代器里的对象的引用。

举个例子, iterator里面有十个对象,你用一次next,第一个就被移出了,所有执行完,迭代器为空,如果你在下面还引用这个迭代器里的对象的话,就会报空指针了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题