By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

Java Object comparison

P: n/a
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You could use the .compareTo method on any object to compare, and all the
objects that are contained within other objects should implement the compare
to method. I.e. all classes that contains objects should override the
compareTo method.

Hope that helped!

~ANDY~
http://www.confusedgeeks.com
"Dheeraj" <dh*******@excite.com> wrote in message
news:29**************************@posting.google.c om...
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj

Jul 17 '05 #2

P: n/a
Implement the Camparable interface, and override the compareTo method.
Then you have to decide how to compare the objects.
fr'instance - if comparing instances of type 'Person' would you consider
salary, height, or weight to decide which is greater-than, less-than, or
equal ??? - its up to the programmer (you) to decide.

"Dheeraj" <dh*******@excite.com> wrote in message
news:29**************************@posting.google.c om...
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004
Jul 17 '05 #3

P: n/a
implemenet the Compare interface as per specification, thats what it's
for. taking a "short-cut" and doing it, "just this once", is not a
short-cut because it's never just this once

- perry
Dheeraj wrote:
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.