If count can be changed, then you need a local variable. If you have multithreading, you need a local variable. It is safer to create a local variable. However, it is not strictly secret.
In this case, it overflows, since the lines are in any case immutable. The count value cannot even change.
This is pretty useless, so in Java 8 it looks like this:
public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { char val[] = value; for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; } hash = h; } return h; }
They no longer have counters, they use value.length , where value is the final char array.
They do char val[] = value , but this is just a reference and is strictly disordered.
It may be some subtle microlevel using a local variable, or perhaps it was done for readability, but it is not optional (and, in my opinion, less readable).
Anubian noob
source share