Skip to main content

hashCode() :

If you only override the hash-code method nothing will happen. Becausehappens, because it always returnreturns a new hashCode for each object asas an Object class.

equals() :

If you only override equalthe equals method, if a.equals(b) is true it means the hashCode of a and b must be the same but that does not happen. Because since you did not override the hashCode method.

Note : hashCode() method of Object class always returnreturns a new hashCode for each object.

So when you need to use your object in the hashing based collection, you must override both equals() and hashCode().

hashCode() :

If you only override hash-code method nothing will happen. Because it always return new hashCode for each object as an Object class.

equals() :

If you only override equal method, a.equals(b) is true it means the hashCode of a and b must be same but not happen. Because you did not override hashCode method.

Note : hashCode() method of Object class always return new hashCode for each object.

So when you need to use your object in the hashing based collection, must override both equals() and hashCode().

hashCode() :

If you only override the hash-code method nothing happens, because it always returns a new hashCode for each object as an Object class.

equals() :

If you only override the equals method, if a.equals(b) is true it means the hashCode of a and b must be the same but that does not happen since you did not override the hashCode method.

Note : hashCode() method of Object class always returns a new hashCode for each object.

So when you need to use your object in the hashing based collection, you must override both equals() and hashCode().

hashCode()hashCode() :

If you only override hash-code method nothing will happen. Because it always return new hash-codehashCode for each object as an Object class.

equals()equals() :

If you only override equal method, a.equals(b)a.equals(b) is true it means the hash-codehashCode of a and b must be same but not happen. Because you did not override hash-codehashCode method.

Note : hash-code() hashCode() method of Object class always return new hash-codehashCode for each object.

So when you need to use your object in the hashing based collection, must override both equals()equals() and hash-code()hashCode().

hashCode() :

If you only override hash-code method nothing will happen. Because it always return new hash-code for each object as an Object class.

equals() :

If you only override equal method, a.equals(b) is true it means the hash-code of a and b must be same but not happen. Because you did not override hash-code method.

Note : hash-code() method of Object class always return new hash-code for each object.

So when you need to use your object in the hashing based collection, must override both equals() and hash-code().

hashCode() :

If you only override hash-code method nothing will happen. Because it always return new hashCode for each object as an Object class.

equals() :

If you only override equal method, a.equals(b) is true it means the hashCode of a and b must be same but not happen. Because you did not override hashCode method.

Note : hashCode() method of Object class always return new hashCode for each object.

So when you need to use your object in the hashing based collection, must override both equals() and hashCode().

Source Link

hashCode() :

If you only override hash-code method nothing will happen. Because it always return new hash-code for each object as an Object class.

equals() :

If you only override equal method, a.equals(b) is true it means the hash-code of a and b must be same but not happen. Because you did not override hash-code method.

Note : hash-code() method of Object class always return new hash-code for each object.

So when you need to use your object in the hashing based collection, must override both equals() and hash-code().