|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
HashCode
How would I add objects so I could get the hash code value for all of them.
Here is my code Code:
/**
* Return a hash code value for this object using the algorithm from Bloch:
* fields are added in the following order: title, year, director.
*/
public int hashCode() {
int result = _title.hashCode();
return result;
}
|
|
#2
|
|||
|
|||
|
I don't have much experience with hashcode, but you could try the xor operator(^):
Code:
/**
* Return a hash code value for this object using the algorithm from Bloch:
* fields are added in the following order: title, year, director.
*/
public int hashCode() {
int result = _title.hashCode();
result ^= year.hashCode();
result ^= director.hasCode();
return result;
}
However, I think there are better ways to do that. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > HashCode |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|