Home  >  Q&A  >  body text

java - not to keep references to the objects from this iterator ?

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

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

大家讲道理大家讲道理2717 days ago815

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 17:16:31

    Is the following understanding correct?

    Don’t save references to objects in iterators.

    For example, there are ten objects in the iterator. If you use next once, the first one will be removed. After all executions are completed, the iterator will be empty. If you still reference the objects in this iterator below, it will Null pointer reported

    reply
    0
  • Cancelreply