The process of inserting is done in two steps:
Step 1 : use the hashCode() to determine the bucket number (in this case it is 17 for all objects), so all objects are inserted in one bucket.
Step 2: use equals() method to check that there is no object already inserted in this bucket that is equal to the willing-to-insert object (and that's to avoid duplicity). Here is the trick, which equals() method is used in this case, the one with Foo parameter or with Object parameter. It is the one with Object parameter that is used, since it is the correct overriding for equals() method inherited from class Object. And since this equals() returns always true it means the set will insert only one element and rejects the others since they are equal to the already inserted element.
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |