Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException

 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic