View Single Post
Old 07-14-2004, 08:21 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,175
Belisarius is on a distinguished road
I've actually done it both ways, and I found I prefer the Comparator route because Comparable always seemed to me the preferred way to define the natural ordering of the objects, whereas Comparator is best when you want to sort objects by different criteria. Setting a static field for the purposes of sorting is a bad idea, IMHO, as it will cause headaches in a multi-threaded environment. Say you want to sort one array of objects in manner A in thread #1, and a different array in manner B in thread #2. Doing it statically really screws you.

I generally just create an anonymous Comparator class for the job. It's atomic, so no problems with multi-threaded, plus you don't need to worry about altering the original class should you want to sort by a different criteria in the future.
__________________
GitS
Belisarius is offline   Reply With Quote