Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to invoke Object hashCode method through String object. How to do it?

public class Test {
    public static void main(String args[]) {


    String s1 = "abc";


        //Here is invoking of overriding String hashCode method.
        System.out.println("hashCode value  "+s1.hashCode()); }
}

Instead of it, I want to get non-overriding Object hashCode method. How do I get it?

like image 271
DEnis Avatar asked Jul 10 '11 14:07

DEnis


People also ask

Will the hashCode () method of object class return the address of the object?

The purpose of the hashCode() method is to provide a numeric representation of an object's contents so as to provide an alternate mechanism to loosely identify it. By default the hashCode() returns an integer that represents the internal memory address of the object.

What is the return type of hashCode () method in the object class?

hashCode() Method The hashCode() is a method of Java Integer Class which determines the hash code for a given Integer. It overrides hashCode in class Object. By default, this method returns a random integer that is unique for each instance.

How does hashCode () method work in Java?

Understanding How hashCode() Works Simply put, hashCode() returns an integer value, generated by a hashing algorithm. Objects that are equal (according to their equals()) must return the same hash code.

Which of the following method is used to find out hashCode of an object?

Java Object hashCode() is a native method and returns the integer hash code value of the object.


1 Answers

call System.identityHashCode(s1) instead.

like image 57
zacheusz Avatar answered Oct 20 '22 08:10

zacheusz