commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <>
Subject Re: [lang] EqualsBuilder
Date Mon, 09 Sep 2002 22:49:58 GMT

1) I would use append as the method name. HashCode and ToString both use
append - it seems to be a mini pattern.

2) The double and float use an unusual comparison strategy. Was there a
reason for this?

3) Double and float could also have an allowed delta version. This would
operate similarly to JUnit asserts.

4) The array handling has to be more complex to handle multi dimensional
arrays. See ToStringBuilder. (Note to myself, I need to do this to
HashCodeBuilder before a release...)

The reflection version definitely helps add usefulness as well. Similar code
should be added to HashCodeBuilder and ToStringBuilder. It might be better
with a 'don't include transient fields' flag.

So my vote is +1 with a little more work (as with all the builders at


----- Original Message -----
From: "Steve Downey" <>
I saw this in the Todo's, and put it together. After building it, I'm not
really sure it pulls it's own weight. Use is along these lines

public boolean equals(Object o) {
  if (!o instanceof MyClass) {
    return false;
  MyClass rhs = (MyClass) o;
  return new EqualsBuilder()
                  .test(field1, rhs.field1)
                  .test(field2, rhs.field2)
                  .test(field3, rhs.field3)



public boolean equals(Object o) {
  return = new EqualsBuilder().reflectionTest(this,o);

the second form uses the setAccessible(true) hack, and so will throw
exceptions under a security manager. OTOH, it's simple for testing code,
which is where I seem to use equals most of the time. E.g. if a round trip
through the database leaves an object equal to itself.

IAC, I haven't done all the JavaDoc comments. I will if anyone thinks this
would be useful for lang.


> --
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message