When debugging, what does the object instance representation "result = {SomeClass@816}" mean?

Dave_dev :

I am debugging my java program, and I have some instance "instance1" of class called "SomeClass". When I evaluate the variable "instance1", it says result = {SomeClass@816}.

What does "@816" actually mean?

I know it is not for sure the hashCode(), is it the instance memory address? If so, how can I "see" the instance address in code? Which method to call on the object itself?

Note: I am using IntelliJ Idea

public class SomeClass {

private String name;
private int id;

@Override
public String toString() {
    return this.name + this.id;
}

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    String objName =  ((SomeClass) o).name;
    return this.name.equals(objName);
}

@Override
public int hashCode() {
    return this.name.hashCode();
}
aran :

That 816 belongs to the identityHashCode (method System.identityHashCode()) of every java Object.

Doesn't matter wether your Class overrides or not the hashcode() method, since identityHashCode() will call the natural hashcode() method of your Object.

From the docs:

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238583&siteId=1