In the Java snippet:
SyndFeedInput fr = new SyndFeedInput();
SyndFeed sf = fr.build(new XmlReader(myInputStream));
List<SyndEntry> entries = sf.getEntries();
the last line generates the warning
"The expression of type List
needs unchecked conversion to conform to List<SyndEntry>
"
What's an appropriate way to fix this?
It looks like
SyndFeed
is not using generics.You could either have an unsafe cast and a warning suppression:
or call Collections.checkedList - although you'll still need to suppress the warning:
Did you write the
SyndFeed
?Does
sf.getEntries
return List orList<SyndEntry>
? My guess is it returnsList
and changing it to returnList<SyndEntry>
will fix the problem.If
SyndFeed
is part of a library, I don't think you can remove the warning without adding the@SuppressWarning("unchecked")
annotation to your method.If you look at the javadoc for the class
SyndFeed
(I guess you are referring to the classcom.sun.syndication.feed.synd.SyndFeed
), the method getEntries() doesn't returnjava.util.List<SyndEntry>
, but returns justjava.util.List
.So you need an explicit cast for this.
Even easier
return new ArrayList<?>(getResultOfHibernateCallback(...))
If you don't want to put @SuppressWarning("unchecked") on each sf.getEntries() call, you can always make a wrapper that will return List.
See this other question
If you are using Guava and all you want to do is iterate through your values:
If you need an actual List you can use
or