Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While debugging java app what information is shown for a variable in a stack frame [duplicate]

Tags:

java

When I debug java app in Intellij Idea I see all variables in a stack frame like this:

object={java.lang.Object@77}

What does the number after "@" mean? It is different from what hashCode returns. hashCode returns number 2a134eca in hex representation which equals to 705908426 in integer representation. Numbers 77 and 705908426 are distinct.

like image 980
user1745356 Avatar asked Oct 21 '13 09:10

user1745356


2 Answers

The @ is the object count number since the app started. So @1012 means the 1012th object created since the app started.

It is not the identity hashcode.

Here is some proof: (I say this because I don't actually know, but I observed it)

public static void main(String [] args) throws Throwable {

    Object object = new Object();
    Object object1 = new Object();
    Integer foo = new Integer(5);
    Object object2 = new Object();
    String str = new String("bar");

    System.out.println("code :" + System.identityHashCode(object));

    RuntimeException exception = new RuntimeException();
    exception.printStackTrace(); //put breakpoint here


}

Output: code :789451787 code :java.lang.Object@2f0e140b

789451787=2f0e140b By the way...

Output from IntelliJ Debugger:

static = org.boon.core.MyClass
args = {java.lang.String[0]@**97**}
object = {java.lang.Object@**98**}
object1 = {java.lang.Object@**99**}
foo = {java.lang.Integer@**100**}"5"
object2 = {java.lang.Object@**101**}
str = {java.lang.String@**102**}"bar"
exception = {java.lang.RuntimeException@**103**}"java.lang.RuntimeException"

I know this empirically, but I don't know the actual implementation, but I think it is related to issues like this:

as3: meaningful object identification while debugging.

like image 69
RickHigh Avatar answered Sep 21 '22 12:09

RickHigh


What does the number after "@" mean?

@ is just a separator

Debuggers use the toString method of an object to display its value. And here is description of default implementation of toString method from the javadocs:

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:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
like image 39
Juned Ahsan Avatar answered Sep 17 '22 12:09

Juned Ahsan