16

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.

user1745356
  • 4,462
  • 7
  • 42
  • 70
  • 1
    Opps.. I meant to do this here... Looks like the allocation count number when the object was created. Create a bunch of objects and you can see that they are sequentially incremented. It might be per thread or per debug run, not sure. I could not find any documents on this... yet. – RickHigh Oct 22 '13 at 02:24

3 Answers3

13

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.

Community
  • 1
  • 1
RickHigh
  • 1,808
  • 20
  • 16
5

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())
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • Sorry, but I still do not understand. By default hashCode supposed to return integer representation of memory address where this object is located. But while debugging my app in Intellij Idea a variable in a stack frame is shown like this object=java.lang.Object@72 while toString method returns java.lang.Object@2a134eca which is classname and hashCode separated by @. numbers 72 and 2a134eca are distinct. So what does 72 mean here? – user1745356 Oct 21 '13 at 09:26
  • 1
    Looks like the allocation count number when the object was created. Create a bunch of objects and you can see that they are sequentially incremented. It might be per thread or per debug run, not sure. I could not find any documents on this... yet. – RickHigh Oct 22 '13 at 02:23
-3

Class of Object followed by its memory address.

In {java.lang.Object@77ddeeff}:
Class name: java.lang.Object
Memory Address: 77ddeeff

So this convention name@address is just like our email addresses like in (abc@gmail.com) abc is located @ gmail.com

Sachin Verma
  • 3,712
  • 10
  • 41
  • 74
  • I am sorry, but both the proprietary Sun's JVM and OpenJDK typically do not use memory addresses when assigning hashcodes. – Tadas S Oct 21 '13 at 09:31
  • I wrote a program and IntelliJ is not using the identity hash code. java.lang.Object@2f0e140b != java.lang.Object@98 – RickHigh Oct 22 '13 at 02:22
  • @eirirlar, its not a made up answer. Object.toString() does return string of internal address (https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()). The reason this answer is bad for here is, at the time I thought intellij console prints toString(), which was/is never the case. – Sachin Verma Jun 19 '18 at 12:23
  • Ok sorry for that – eirirlar Jun 19 '18 at 17:07