So okay, hashcode is int and so there are only 4294967296 distinct hashcodes. It is not a little number, but in modern systems there could be definitely much more objects.

In a

very good book by Joshua Bloch I have read that there is a probability that two consequently created objects will have an equal system identity hashcode. Actually from the time of publishing that book major version of Java was released and the situation has improved dramatically. But still 2

^{32} is a very little number for objects. And still two consequently created objects may have an equal identity hashcode:

` private static final int SIZE = 500000000;`

public static void main(String[] args) {

int count = 0;

for (int i = 0; i < SIZE; i++) {

if (new Object().hashCode() == new Object().hashCode()) {

count++;

}

}

System.out.println(count + " of " + SIZE + " consequently created pairs of objects had equal hashcodes");

}

On my machine that produced the following output:

16 of 500000000 consequently created objects had equal hashcodes