wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics - Unchecked conversion warning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics - Unchecked conversion warning" Watch "Generics - Unchecked conversion warning" New topic
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: 18914
    
  40

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics - Unchecked conversion warning