Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why extra var2 byte array is used in hashCode method of StringLatin1 utility class?

Tags:

java

java-11

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;
}

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 java.lang package, there is a utility class called StringLatin1. This class has hashCode method which will be called from String class's hashCode method, if current string value is latin.

PS: I use Java 11.

like image 530
Seydazimov Nurbol Avatar asked Mar 10 '26 07:03

Seydazimov Nurbol


1 Answers

Whatever current code you have posted is not the real code; it's the decompiled code which may vary from decompiler to decompiler and therefore you can not rely on it.

like image 61
Arvind Kumar Avinash Avatar answered Mar 11 '26 21:03

Arvind Kumar Avinash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!