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?
Best Answer
This is a common problem when dealing with pre-Java 5 APIs. To automate the solution from erickson, you can create the following generic method:
This allows you to do:
Because this solution checks that the elements indeed have the correct element type by means of a cast, it is safe, and does not require
SuppressWarnings
.