When I new a Hashtable, why the put method is invocated?

hashtable, java

Solution

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?

Problem

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?

Original source