Using Comparable for generic Objects
1 posts in topic
Flat View  Flat View

Posted By:   kevin_chen
Posted On:   Saturday, March 9, 2002 06:50 AM

Let's say I have an Object obj, which I know will be a Comparable type, but I don't know exactly what data type so I cannot cast it (i.e. it could be a String or Integer, etc). The dilemma is that I cannot use obj.compareTo since the Object class does not implement Comparable. How would I go about making this functionality in code? (It can be assumed that the argument for compareTo has the same data type as obj).

Re: Using Comparable for generic Objects

Posted By:   Eric_Lindauer  
Posted On:   Wednesday, March 20, 2002 07:32 AM

((Comparable) obj).compareTo ( theOtherObject );

Hope this helps.

About | Sitemap | Contact