Hi all,
I am a bit confused about the hashCode method. By default (ie. no overriding), hashCode() returns the memory address.
But since a & b were created using New, wouldn't the memory address be different ? This is easily validated by performing an a==b compare which returns false.
If the memory address is different, why does a.hashCode() and b.hashCode() return the same value ??
Here's the code I used to
test ... (the output is just "hashcode equal) ...
------------------------------------------
class Testhashcode {
public static void main (
String [] arg) {
String a = new String("ABC");
String b = new String("ABC");
if (a == b) System.out.println("== equal");
if (a.hashCode() == b.hashCode()) System.out.println("hashcode equal");
)
}
[ July 08, 2003: Message edited by: bennido kool kat ]