Your explanation is the most plausible. This is to insulate the implementation of HashMap from the effects of someone overriding the entrySet()
method in a subtype.
The only other explanation I can think of is that this is left over from some older version of the class, and I wouldn't expect that the Java developers would have let that happen here. (This is code has lots of eyeballs on it ...)
Either way, it probably makes no difference to performance. The JIT compiler is likely to inline the call ... except in the case where there is a subclass of HashMap
that does override entrySet()
.