![]() |
|
|||||||
| SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Cleanin up Java unchecked conversions
I'm in the process of cleaning up some Java code and can't figure out how to eliminate an "unchecked conversion" warning I'm getting. Here is the code:
Code:
// Get the RSSItems in a LinkedList.
LinkedList<RSSItem> ChanItems = new LinkedList<RSSItem>();
ChanItems = rsschan.getItems();
I'd like to avoid using @SuppressWarnings because that might hide warnings I really need to see. What is the best way to accomplish this?
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
|
#2
|
||||
|
||||
|
Quote:
Adding @SuppressWarnings("unchecked") just above the statement... Code:
// Get the RSSItems in a LinkedList.
@SuppressWarnings("unchecked")
LinkedList<RSSItem> ChanItems = new LinkedList<RSSItem>();
ChanItems = rsschan.getItems();
Code:
// Get the RSSItems in a LinkedList.
LinkedList<?> ChanItems = new LinkedList<RSSItem>();
ChanItems = rsschan.getItems();
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
|
#3
|
|||
|
|||
|
Quote:
You have a few options. Although, first looking at the code - the call to "new LinkedList<RSSItem>()" is unnecessary. In your second step you are setting the ChanItems to the value returned by rssChan.getItems(); So effectively that code could become Code:
LinkedList<RSSItem> ChanItems = rsschan.getItems(); Code:
LinkedList<RSSItem> chanItems = rssChan.getItems(); ![]() For the unchecked warning question. You are getting the error for a good reason, as you speculated you are asking the compiler to guarantee that only Objects of type RSSItem will be in the list named chanItems, however the method you are calling to retrieve that list doesn't use generics and therefore does not guarentee (via generics - it may via its javadoc) that the LinkedList will only have objects of type RSSItem. (1) If you know that rssChan.getItems(); will always return a LinkedList that contains only RSSItems and you want your program throw a ClassCastException in the case where it does not, there is nothing wrong with using @SuppressWarnings("unchecked") at the site of the call - that will not hide other errors as long as you scope it just to the variable declaration: Code:
@SuppressWarnings("unchecked")
LinkedList<RSSItem> chanItems = rssChan.getItems();
Code:
List<RSSItem> chanItems = new LinkedList<RSSItem>();
for(Object object : rssChan.getItems()){
if(object instanceof RSSItem){
RSSItem rssItem = (RSSItem) object;
chanItems.add(rssItem);
}
else{
Log("OMG Ponies! Unexpected object type in return list");
}
}
|
|
#4
|
||||
|
||||
|
Thanks to both. I didn't realize I could use @SuppressWarnings() at the individual statement level so I think I'll just use that.
I know the new LinkList<> is not necessary, I was juts doing some testing
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HBO-HD Conversions Have No Sound | EdwardATeller | SageTV Software | 0 | 03-03-2008 02:37 PM |
| Automatic Conversions | EdwardATeller | SageTV Software | 2 | 03-01-2008 05:56 PM |
| Multiple Conversions at once? | SnakeJG | SageTV Software | 0 | 05-16-2007 12:27 AM |
| Conversions | Jackal24 | SageTV Software | 3 | 03-12-2007 10:35 AM |
| Conversions Waiting | rsagetv99 | SageTV Beta Test Software | 6 | 12-04-2006 07:52 PM |