Home > Net >  Why VSCode shows strange "@number" (like int[10]@9) for arrays when debugging?
Why VSCode shows strange "@number" (like int[10]@9) for arrays when debugging?

Time:09-29

This was a simple binary search code and while I was debugging it for my better understanding, I got this remark a = int[10]@9 in the debugging panel - what does it mean (especially "@9" part after the type)? int[10]@9 remark while debugging

/**
 * BinarySearch
 */
public class BinarySearch {

    public static void main(String[] args) {
        int a[]={1,3,5,14,22,37,54,77,99,110},target=99 ;
        System.out.println(binarysearch(a,target)); 
    }
    static int binarysearch(int a[], int target)
    {
        int s=0,e=a.length-1;
        int mid;
        while(s<=e)
        {
            mid=s e/2; //mid= 4 
            if(target<a[mid]) //false
            e=mid-1;//
            else if(target > a[mid])//true
            s=mid 1;
            else if(a[mid]==target) {
            return mid;
            }

        }
        return -1;
    }
}

CodePudding user response:

Some debuggers annotate objects with an additional unique number reflecting the "identity" of the object, so you can easily tell if two different references are referencing the same object, versus two objects with the same values. This is not always the "identity hash code" referred to in the other answer, but can e.g. refer to "this was the Nth object allocated" in a test scenario.

CodePudding user response:

By default, the debugger shows the toString() value of an object. As arrays don't override the toString() method, it just uses the default implementation inherited from Object.

As the documentation says here, the string is constructed in the following way:

getClass().getName()   '@'   Integer.toHexString(hashCode())

So, that's exactly what you're seeing: the class name, the '@' symbol, and the hash code.

  • Related