• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics - Unchecked conversion warning

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Henry Wong
author
Marshal
Pie
Posts: 21015
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic