| Author |
Generics - Unchecked conversion warning
|
O. Ziggy
Ranch Hand
Joined: Oct 02, 2005
Posts: 430
|
|
I cant figure out why i am getting this warning.
For the following bit of code
both setTimes and setSubset are of type TreeSet<Integer>. I looked at the API and it is saying that TreeSet.headSet returns a NavigableSet<E> which has just confused me even more.
--
|
 |
Goerch Mosi
Greenhorn
Joined: Dec 27, 2010
Posts: 8
|
|
Hello O.Ziggy,
because you forgot to define the type at the row where you use headSet(1600)
Try this one. ;-)
setSubset = ( TreeSet<Integer>)setTimes.headSet(1600);
|
OCPJP - 80%
|
 |
O. Ziggy
Ranch Hand
Joined: Oct 02, 2005
Posts: 430
|
|
Thanks
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
O. Ziggy wrote:
I looked at the API and it is saying that TreeSet.headSet returns a NavigableSet<E> which has just confused me even more.
NavigableSet is an interface that is implemented by the TreeSet class. A TreeSet IS-A NavigableSet. A NavigableSet is not necessarally a TreeSet. So... it may be a good idea to use NavigableSet instead, as the headSet() method may not always return an object that may be casted to TreeSet, in future implementations.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: Generics - Unchecked conversion warning
|
|
|