java - overriding hashCode, why is this.hashCode() not used? -


when overriding equals() , hashcode() methods in java why isn't used often:

public int hashcode() {     return (int) this.hashcode(); } 

or above prime introduced:

public int hashcode() {     final int prime = 31; //31 common example     return (int) prime * this.hashcode(); } 

is bad practise or not work?

the method:

public int hashcode() {     return (int) this.hashcode(); } 

would lead stackoverflowerror because recurse infinitely, unless replace this super. second method has same problem.

in addition, casting value of type int int useless well.

if not provide useful new method, don't override it.


Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -