Re: output reference meaning
josh wrote:
Hi, in Java we know that pointers are used behind the scenes...but how
?
and if I've a simple code like:
int a[] = new int[3];
System.out.println("a reference is: "a);
I think your actual code must have a "+" sign that is missing from the
example. It is better to copy-paste, rather than retype.
Also, saying "a reference is" is a little misleading. You are actually
printing out the result of a.toString(), which for some values of a will
tell you things about the object, not the reference.
what does this output mean?
a reference is: [I@1a8c4e7
"[I@1a8c4e7" is a.toString().
To find out what that means, start with Object's toString:
getClass().getName() + '@' + Integer.toHexString(hashCode())
So "[I" is the name of a's class.
The java.lang.Class API documentation will tell you that the name for an
int array is "[I".
The Object hashCode documentation says "As much as is reasonably
practical, the hashCode method defined by class Object does return
distinct integers for distinct objects. (This is typically implemented
by converting the internal address of the object into an integer, but
this implementation technique is not required by the JavaTM programming
language.)"
So 1a8c4e is certainly a's hashCode, and may be based on its address.
Patricia