I have a class with compare method. The method takes two objects as arguments. With java reflection I was able to get all the private and protected field and with some fancy stuff check their return types and do what I want to do with them.
This is good for me personaly. I know what I want to do so I just compare two objects of same type and thats all.
BUT ... this is used by many people ...and they sometimes are unable to read a Javadocs and comments and other stuff I put there so I have to check if they are passing object of same type. For example you have : Car a, Car b , Truck a, Truck b ... and so on.. I need to check if the two passed arguments are actually the same type for comparing (Car with car , Truck with truck..)
So ... I dont know the stuff.. Should I use the reflection for listing the size of all fields and then check if all the fields have the same name ? Or is there a better solution ? Becouse writing something like if the fieldsOfA.size is same as fieldOfB.size ... and then for loop for this if they are same to check the names looks kinda weird..
Also another problem. Those objects have lists of some other object - for example Car has a list of Wheels.. And you are comparing the wheels with other car. They have like Wheel 1 , Wheel 2 , Wheel 3, Wheel 4 in list.. and the second car has Wheel1, Wheel 2, WHeel 4 and WHeel 3 ..
So the objects are same , but just have switched positions..is there a way to prevent this ? I have a tracking code that stores every difference in those objects.. So if they have different positions it gives me two changes.. Wheel 3 is different from other car and wheel 4 is different on other car..
But they are still the same ... I don't know how to solve this with reflection ... Any Ideas ?
o1.getClass() == o2.getClass()
.