Java – What does it mean for the jvm address of an object to be 0?

What does it mean for the jvm address of an object to be 0?… here is a solution to the problem.

What does it mean for the jvm address of an object to be 0?

I have

an object Mutation to which I have “new”. But when it prints out with toString(), the object says Mutation@0. This doesn’t seem very good to me. What might this mean?

Solution

That is, the unsigned hexadecimal representation

As per Docs of toString() method in Object class

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

Zero in the sense that the hash code has not yet been calculated.

Source Code:

   public String toString() {
237        return getClass().getName() + "@" + Integer.toHexString(hashCode());
238    }

Related Problems and Solutions