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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -