File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ClassCastException" Watch "ClassCastException" New topic
Author

ClassCastException

geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 78
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

To sort things, you need to compare them. Can you compare Integers with Strings or Booleans ? Look at the API for Arrays#sort(Object[]). That's what they mean by "all elements in the array must be mutually comparable".


[My Blog]
All roads lead to JavaRanch
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I think it's because your array is of type Object. and object doesn't implements comparable. Although the elements are all comparable, but not to each other....


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think it's because your array is of type Object.

It would be fine is the content of the array would be comparable to each other. Like :
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException