If you want a general method which works for all classes (or at least, most classes) without you having to write custom code for each class, I guess you could use somethign based on reflection.
Jakarta Commons Lang has an
ObjectUtils class with an equals() method that seems to do this. I"ve never tried it, but it looks promising. Something I have tried successfully is to use
XStream to make a simple xml serial form of each object, and compare the strings. (May not be the fastest way to implement equals, but so far it's been very robust - and when used with
JUnit's assertEquals(
String, String) method, gives a nice understandable error message showing the difference between the two objects you were asserting to be equal.