Unchecked Warnings

I'm writing a web application using a proprietary Java 1.4 based content management API. When I'm working with Collections, Lists, etc. I get unchecked warnings. Here's an example:

/*

* References to generic type List<E> should be parameterized.

*/

List searchResults = searchAPI.search(WebUtils.getPropsWithDate(), getSCSContext(),"dDocName LIKE " +"\'" + contentId +"\'", 20).getResults();

/*

* The expression of type List needs unchecked conversion to conform to

* List<ISCSActiveSearchResult>

*/

List<ISCSActiveSearchResult> searchResults = searchAPI.search(WebUtils.getPropsWithDate(), getSCSContext(),"dDocName LIKE " +"\'" + contentId +"\'", 20).getResults();

I know I can use the @SuppressWarnings("unchecked") annotation but I'd rather just write warning free code if possible.

I apologize if this is rather basic but I haven't had much luck finding a solution. Anything help is greatly appreciated!

[1223 byte] By [Anthony_Smitha] at [2007-11-27 11:12:56]
# 1

Good news! I just discovered the <?> generics operator... thing (sorry, I'm not sure what it's called). So to fix my example below.

List<?> searchResults = (List<?>) searchAPI.search(WebUtils.getPropsWithDate(), getSCSContext(), "dDocName LIKE " + "\'" + contentId + "\'", 20).getResults();

I'm stuck on something else now though. I'm working with the Connections sort method now and I'm running into the following problem.

/*

* Type safety: Unchecked invocation sort(List, Comparator) of the generic

* method sort(List<T>, Comparator<? super T>) of type Collections

*/

Collections.sort(workflowQueue, new WorkflowItemsComparator());

Same thing happens if I use.

/*

* Type safety: Unchecked invocation sort(List, Comparator) of the generic

* method sort(List<T>, Comparator<? super T>) of type Collections

*/

Collections.sort((List<?>) workflowQueue, new WorkflowItemsComparator());

Any ideas?

Anthony_Smitha at 2007-7-29 13:57:45 > top of Java-index,Core,Core APIs...