When debugging a java application, what information is displayed for the variable in the stack frame

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

object={ java.lang.Object@77 } 

What does the number after "@" mean? It is different from what hashCode returns. hashCode returns the number 2a134eca in hexadecimal, equal to 705908426 in integer. The numbers 77 and 705908426 are different.

+6
source share
3 answers

From the moment the application starts, the @ value is calculated by the number of objects. So, @ 1012 means the 1012nd object created since the application started.

This is not a hashcode identifier.

Here is some evidence: (I say this because I really don't know, but I watched 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 ...

Exiting 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 do not know the actual implementation, but I think this is due to such problems:

as3: meaningful identification of the object during debugging .

+6
source

What does the number after "@" mean?

@ is just a delimiter

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

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

  getClass().getName() + '@' + Integer.toHexString(hashCode()) 
+2
source

Class An object followed by its memory address.

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

So this @ name name matches our email addresses such as ( abc@gmail.com ) abc is @ gmail.com

-1
source

Source: https://habr.com/ru/post/956395/


All Articles