Real HashCode of an Object
https://www.geeksforgeeks.org/system-identityhashcode-method-in-java-with-examples/
Scanner in = new Scanner(System.in);
String one = "something";
String two = "something";
String three = new String("something");
String four = in.nextLine();
System.out.println(one.hashCode());
System.out.println(two.hashCode());
System.out.println(three.hashCode());
System.out.println(one == two); // true
System.out.println(one == three); // false
System.out.println(one == three.intern()); // true
System.out.println(one == four); // false
System.out.println(one == four.intern()); // true
int oneHash = System.identityHashCode(one);
int twoHash = System.identityHashCode(two);
int threeHash = System.identityHashCode(three);
int fourHash = System.identityHashCode(four);
System.out.println(oneHash);
System.out.println(twoHash);
System.out.println(threeHash);
System.out.println(fourHash);
Комментарии
Отправить комментарий