Any way to see hashcode of primitive types?

Retrieving the base DS ... I read that a method hashCode()for a primitive type intis available, and if called in int, it will throw an error

error: int cannot be dereferenced

Does this mean that if int n = 10, then it HashCodewill also be 10 ??

If I still need to see the hascode for intin the program below, is there a way to see it, for exampleInteger Wrapper

public static void main(String []args){
       String me = "hello";
       int n = 10;

       int h1 = me.hashCode();
       int h2 = n.hashCode();

       System.out.println(h1);
       System.out.println(h2);
     }
+3
source share
7 answers

You cannot call methods on primitive types.

ndeclared as int. He has no methods.

It makes no sense to think how

If I still need to see hascode for int in the program below

Integer hashCode()

Integer.valueOf(n).hashCode()

Integer#hashCode()

public int hashCode() {
    return value;
}

value - int, .

, int n = 10, HashCode 10??

int -. Integer int, .

+8

. . ,

 int h2 = new Integer(n).hashCode();

Wrapper int .

+2

int Java, int hashCode().

+1

int Java. . , Integer - int.

System.out.println(new Integer(n).hashCode());

, .

0

(Java 8)

Java 8 - . .

( ?), OpenJDK, , Google Guava Java.

Java 8 JDK, Guava, hashCode, .

... ..

0

, -. -, .

Integer - , , java.util.HashSet, , .

public int hashCode() {
    return value;
}
0

All Articles