我看了一下hashcode
許多文章和等於及其相互關係的船。 到目前爲止,我的理解是每個object
都具有等於和hashcode
的功能默認.As java class
有這些功能。 現在hashcode
表示它返回一個對象的內存地址。 hashcodes
默認是唯一的。當一個對象被創建時,你將得到一個唯一的代碼。
- 現在我的問題是,當你
override
的equals
功能按 規則,我們需要重寫hashcode
功能..? - 因此,我們實現了
hashcode
函數以及等於 方法,但hascode
實現是沒有用的。 而且
hashcode
如何在hashmap
使用和collection
框架hashtable
..?class person{ string name; string employer; boolean equals(Object o){ person per=(person)o; if(per.employer==this.employeer){ return true } return false; } int hashcode(){ return 0;//what ever i do in hashcode does it really effect any thing..as the equals does //the comparison for me and gave me the result } }
和hascodes
如何在hashmap
使用和hashtable
感謝,