You would expect that "Hello World!!!" is printed in your example code, and indeed it is if you run it (did you try?). But HashSet and TreeSet don't specify anywhere when they are going to call hashCode(), so there is no guarantee that it will always be called when you put an object in the set.
Yes. I have tried that code and seeing the Hello World in the console, but like threading, sometimes the thing I see in console may not be the only way it can be displayed, and so I just want to confirm that sentence must print out when add is called. And after my understanding on your
word, it is no guarantee that hashCode method must be called when calling add method in Set implementation (say HashSet<
Test>), am I correct?