Why did java rewrite hashCode? when rewriting equals

Why does java rewrite hashCode? when rewriting equals
I think there are two points to pay attention to:

  1. whether hashCode rewriting depends on the business. Open developers can rewrite this method. This may be the case. For example, if we compare only some of the attributes of object, we consider them to be equal without comparing other attributes.
  2. overrides the java object hashCode method to avoid unwanted collisions and collisions in some algorithms. For example, in the use of its HashMap,HashSet.
Mar.14,2021

I think the main point is the second point, avoiding collisions and conflicts.
hashCode is used to identify a single object in a collection class, and I think it is necessary to rewrite it.

and when the programmer's business entity object is created, it may be reasonable to use it, but others do not need to pay special attention to hashCode when using the object.
apache commons provides help methods, which are very useful:

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35302-2bf6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35302-2bf6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?