Why use an extra var2-byte array in the hashCode method of the StringLatin1 utility class?… here is a solution to the problem.
Why use an extra var2-byte array in the hashCode method of the StringLatin1 utility class?
The current code is:
public static int hashCode(byte[] value) {
int h = 0;
byte[] var2 = value;
int var3 = value.length;
for(int var4 = 0; var4 < var3; ++var4) {
byte v = var2[var4];
h = 31 * h + (v & 255);
}
return h;
}
The possible code is:
public static int hashCode(byte[] value) {
int h = 0;
int var2 = value.length;
for(int var3 = 0; var3 < var2; ++var3) {
byte v = value[var3];
h = 31 * h + (v & 255);
}
return h;
}
In the java.lang
package, there is a utility class called StringLatin1
. This class has a hashCode
method that is called from the hashCode
method of the String
class if the current string value is Latin.
PS: I use Java 11.
Solution
Whatever the current code you release is, it’s not real code; It is decompiled code and may vary from decompiler to decompiler, so you cannot rely on it.