Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Hash Code



Hi!
I have just now discovered that "new Object().hashCode()" does return different valus from a loop, but returns same values when programm is restarted!

public static void main(String[] args) {
        for(int i = 0; i < 10; i++){
            System.out.println(new Object().hashCode());
        }
}

For instance i run above program 5 times i get same output!

Test 1:

run:
4384790
9634993
1641745
11077203
14576877
12677476
33263331
6413875
21174459
827574
BUILD SUCCESSFUL (total time: 0 seconds)

Test 2:

run:
4384790
9634993
1641745
11077203
14576877
12677476
33263331
6413875
21174459
827574
BUILD SUCCESSFUL (total time: 0 seconds)

...

Can any body explane, why i get always the same result.

Tnx!