I am reading the code of Hashtable
and am confused and have some questions.
I coded like this:
Hashtable table = new Hashtable();
table.put(table, 1);
int code = table.hashCode();
I have two questions:
When I invoke the hashCode
method just like the third line code, why isn't it an endless loop? I think it is an endless loop.
When I debug this code, I found that code new Hashtable()
will cause the invocation of put
method, why?
According to the OpenJDK source I'm reading, there's a guard written specifically to guard against the case where a Hashtable contains itself.
I don't see any reference to put
within the constructor. Do you have a trace you could post in your answer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With