Why ClassCastException?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mohammad_rizwan
Posted On:   Tuesday, April 8, 2003 06:08 AM

why class cast exception comes if we sort the

collection of objects, where object doesnt

implement comparable interface. I thought it

should give compareTo() method does not found.

or no such method defintion.
Thanks.
Rizwan Md.

Re: Why ClassCastException?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, April 8, 2003 07:36 AM

Hi,

Because to sort objects, the JVM tries to cast each object of the colletion to a Comparable object.

Since the object doesn't implement that interface, there you get the ClassCastException.
About | Sitemap | Contact