Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

<K extends Comparable> when casting to Comparable, warning

843793Sep 21 2008 — edited Sep 21 2008
Hi, I'm getting a warning "Java uses unsafe or unchecked operations." when I cast a generic type K to a Comparable.

I've used generics <K extends Comparable<K>> in my class definition and my method takes a parameter of type K.
I then have this line:
 if(((Comparable)key).compareTo(root.getKey())==0) 
My question is: why do I get this warning? Is it just because the K object really gets passed in as an Object object? and is there any way to get rid of this warning?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2008
Added on Sep 21 2008
4 comments
249 views