Unchecked warning with generics and compareTo
Hi,
I've worked on this quite a while, checking the forums and tutorials, but cannot seem to get the unchecked error to go away. I know I can use @SuppressWarning, but I'd like to avoid that. Is there a way to declare my "data" member as a non-raw Comparable type?
publicclass DataItem<T>implements Comparable<DataItem><?extends T>>{
private T data;
public DataItem( T data ){
this.data = data;
}
public T getData(){
return data;
}
publicint compareTo(DataItem<?extends T> o){
if ( datainstanceof Comparable )
return ((Comparable)data).compareTo( o.getData() );
else
return data.toString().compareTo( o.getData().toString() );
}
}
Error is as follows:
"c:\Program Files\Java\jdk1.6.0\bin\javac" -Xlint:unchecked DataItem.java
DataItem.java:14: warning: [unchecked] unchecked call to compareTo(T) as a member of the raw type java.lang.Comparable
return ((Comparable)data).compareTo( o.getData() );
^
1 warning
Thanks,
Dave

