Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThis conversation is a bit reversed. Usually, developers override `equals` and forget `hashcode`. I don't see how `HashMap<Object, Object>` would be ok in this case. Where did your `assertFalse` come from? I can't find it in `HashMap`. From what I see, `HashMap` only uses `hashCode`, not `equals`. So, two different type objects could collide, and that's why I'm leery of `Objects.hashCode(Object[])`. I agree that it's always important to override `hashCode` and `equals` as a pair, but from my understanding, if two objects have the same hash code, they should be equal and vise versa.
      singulars
    2. CO@nondescript1 - I guess you misunderstood equals and hashcode contract - you must override hashcode when you override equals and two equal objects should produce same hashcode but it's not vice versa. the general contract of Object#hashcode says - It is **not required** that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
      singulars
    3. CO@nondescript1 - and about your statement "From what I see, HashMap only uses hashCode, not equals" > how you conclude this? can you point me the doc/spec link? As per my understanding the HashSet will store the object in hash buckets by using hashcode value but will call equals on it to compare the equality. So if your Teacher and Student returns the same hashcode they will be placed in the same bucket but if you want to get Teacher from Map it will check the equals and then will return you the valid Teacher or null, so there won't be any collision.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload