commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject [Lang] Add hashcode generating methods to Lang
Date Sun, 30 Jun 2002 23:02:44 GMT
Proposal from previous thread:
> > 2) add hashCode building methods to Objects, or its own class based on
best
> > hashCode practice

What I have in mind is as follows:
public class Foo {
 private String a;
 private long b;
 private boolean c;

public int hashCode() {
  int total = 17;  // odd magic number
  total = HashCodeUtils.build(total, a);
  total = HashCodeUtils.build(total, b);
  total = HashCodeUtils.build(total, c);
  return total;
}

The HashCodeUtils class would contain one method per primitive type, and one
for objects. the implementation would add to the passed in total as per the
rules in Joshua Blochs Effective Java book.

I suggest a separate class for this just for clarity, but the methods could
sit on Objects.

Stephen


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message