2

Lets say i have this code :

Integer[] a= new Integer[5];
System.Out.println(((Object)a).toString());

the output is get is

[Integer@89fbe3

what is the meaning of 89fbe3 ? is this some kind of address ? hash code? is it unique for each object? , and if so- if its a multi-threaded program , is it still unique ?

thanks !

Tom
  • 16,842
  • 17
  • 45
  • 54
RanZilber
  • 1,840
  • 4
  • 31
  • 42

5 Answers5

4

It's the result of System.identityHashCode(Object x);

which is the default implementation of every object's hashCode()...

from the Object javadoc:

getClass().getName() + '@' + Integer.toHexString(hashCode())
Mark Peters
  • 80,126
  • 17
  • 159
  • 190
david van brink
  • 3,604
  • 1
  • 22
  • 17
3

The 89fbe3 is a hex version of the hash code. The [I means an array of ints (I'm surprised you get that with an Integer[], are you sure it wasn't an int[]?)

Some others:

  • [L<typename>;: an array of reference type "typename" (e.g. [Ljava.lang.Integer)
  • [J: an array of longs
  • [B: an array of bytes

etc.

Mark Peters
  • 80,126
  • 17
  • 159
  • 190
2

It is the identity hash code of the object (you can think of it as the address of the object), along with some type information.

[ = array I = Integer

time4tea
  • 2,169
  • 3
  • 16
  • 21
1

I think that while technically all the answers are correct, the real answer is "NO". This number has no meaning and you can make absolutely no assumptions about it.

MK.
  • 33,605
  • 18
  • 74
  • 111
  • So is there any way to determine between two arrays in runtime? – RanZilber Jan 14 '11 at 21:31
  • The number is the hash code in hex, which for a method that doesn't override hash code is the (somewhat) unique object ID. This can be used to see if two objects are the same instance. – Steve Kuo Jan 14 '11 at 21:34
  • @RanZilber I think you accidentally the question. – MK. Jan 14 '11 at 21:34
  • It's good for checking whether the two variables you assumed to be referring to the same instance, actually do. – biziclop Jan 14 '11 at 21:34
  • @Steve Kuo '==' can be used to see if 2 objects are the same instance. equals() can be used to see if two objects are "the same" according to their creator. I don't know what the default toString() can be used for. – MK. Jan 14 '11 at 21:35
  • @biziclop what is wrong with '=='??? – MK. Jan 14 '11 at 21:37
  • I think this is a correct answer as well. If you need to absolutely identify an Object you need to retain a reference to it and use `==` to see if it's the same as another Object. Just beware of memory leaks taking that route. – Mark Peters Jan 14 '11 at 21:40
  • @MK I was thinking about printing the default object string into a debug log file for manual observation, not using it in actual code. – biziclop Jan 14 '11 at 22:13
-1

It's the memory address of the object which is what the default toString() implemented in the Object class does. It is also the default hashCode().

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88