ClassCastException « Sort « Java Collection Q&A

Home
Java Collection Q&A
1.algorithm
2.array
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
10.ArrayList
11.collection
12.comparator
13.Development
14.Garbage Collection
15.Generic
16.hash
17.HashMap
18.HashTable
19.iterator
20.LinkedList
21.List
22.Map
23.queue
24.Set
25.Sort
26.tree
Java Collection Q&A » Sort » ClassCastException 

1. Question about Comparable and ClassCastException    coderanch.com

Originally posted by Jeanne Boyarsky: Thomas, Set needs to know whether the object is already in the set. To figure this out, it wants to call the compare method. Since this method is defined on the Comparable interface, Set needs to cast the object first. This casting makes the compare method available.

2. java.lang.ClassCastException: Employee cannot be cast to java.lang.Comparable    coderanch.com

Edit: reply to Ravi's question why it was only required for TreeSet It isn't. You would have had the same error when using these objects in a TreeMap, or when they were in a List and you sorted it using Collections.sort(List). Actually, the latter would have given a compiler error since Java 5.0, but before it would have given the error. ...

3. ClassCastException : Comparable    forums.oracle.com

Actually, All of the BlockingQueues will have a blocking take() with FIFO ordering with the exception of: 1) DelayQueue where order is order of removal is defined by the longest time since the delay expired and 2) PriorityBlockingQueue (which you were using) which defines order of removal based on the natural ordering of the elements (or of a Comparator), not FIFO. ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.