I want to compare two Java objects without overriding the equals method . Since I need to redefine the equals method in n number of classes that I have, I need a general utility method where we can compare two Java objects.
Sort of:
A a1,a2; B b1,b2; C c1,c2; ----- ----- boolean isEqual1 = new ObjectComparator().isEquals(a1 , a2); boolean isEqual2 = new ObjectComparator().isEquals(b1 , b2); boolean isEqual3 = new ObjectComparator().isEquals(c1 , c2);
Please help me write a general utility to compare any Java objects.
Hopefully using the Field class and getClass , we can achieve it. Please guide me.
source share