Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Some Map implementations have an entrySet() method returning a set with an iterator method returning an iterator which returns the same (as in object identity) Map.Entry on each call to next(). This works well in the usual case where each entry is discarded (effectively becomes garbage) before next() is called. However, if entries are saved, perhaps to build up other collections or arrays, they will need to be defensively copied by the caller before next() is called. This is an optimization to prevent garbage being generated on each call to next(). However, the cost of creating many small short-lived objects is much lower than it used to be in most implementations, and is likely to get even lower as VM optimizations such as escape analysis and stack allocation are implemented. Therefore such error-prone optimizations such as this one should be removed at some point.
|