Rob Prime wrote:Comparable is generic too. The declaration should be That "? super T" is to ensure that T can also be java.sql.Timestamp which is a Comparable<java.util.Date>.
That should solve the warning, but the ClassCastException will still exist. Can you show us the relevant parts of MyListADT? Especially the related fields and its constructor, since that's where the exception is coming from.
Rauhl Roy wrote:
kemp may i know the answer to my question?
Janeice DelVecchio wrote:Rob -
I like your example.
In the first example, how is the "old a" ever able to be GC?
I was under the impression that string literals hung out in the pool forever..... of course I'm incredibly dense when it comes to GC and strings.....
E:\practice>javac -Xlint MyArrayList.java
MyArrayList.java:154: warning: [unchecked] unchecked method invocation: <T>smaller(T,T) in MyArrayList is applied to (T,T)
if(list[i] == smaller(list[smallest], list[i]))
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Comparable;