Alex Rivera | Logout

Implementing `hashCode()` for very simple classes

Asked 2009-01-30T19:07:17.020
9

I have a very simple class with only one field member (e.g. String). Is it OK to implement hashCode() to simply return fieldMember.hashCode()? Or should I manipulate the field's hash code somehow? Also, if I should manipulate it, why is that?

Edit
Report

1 Answer

12

If fieldMember is a pretty good way to uniquely identify the object, I would say yes.

answered 2009-01-30T19:10:29.980

Your Answer