Compare two dvos of same class
How will I compare two dvo objects? . These dvo objects belongs to same class & can be serialised.
ex:
class Dog implements Serializable{
private String name = null;
private int age = 0;
// getter & setters
}
Dog dog1 = new Dog();
Dog dog2 = new Dog();
How will I check dog1 & dog 2 are equal. Please do not say me to override the equal method. This Dog class is just an example, but I want to implement the solution to a complex dvo where to override a equal method is combursome for me. So I want a generic solution which I can implemnet on any type of dvo.
[634 byte] By [
prasad_a] at [2007-10-2 15:35:14]

Don't want to override the equals() method? Well, that's the right way to do it so that's what you should do. But if you don't want to do that, you could override the compareTo method. In any case you're going to have to do some programming.
The only good solution is to implement equals(). The idea of comparing the serialized bytes is interesting if it works, but it will not be nearly as quick as a typical equals() method, and more importantly, your hashcode will not be equivalent to equals, which is a bad idea.
Most decent IDEs will implement the hashCode() and equals() method for you automatically by comparing any instance variables you select.