• Post Reply Bookmark Topic Watch Topic
  • New Topic

Warning with Type safety  RSS feed

 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

With java 1.6, the Query.getResultList() causes the following warning:

Type safety: The expression of type List needs unchecked conversion to conform to Collection<Service>


The java code is shown below:



I have tried (List<Service>) q.getResultList(), but warning is still persist.

What is the best solution to get rid of the warning wtihout using supress_warnings annotaiton?
I also don't want to create a separate function to cast each element in a loop.

Your suggestion is very appreciated.

Thanks
Sam
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing you can do is use a @SuppressWarnings("unchecked") annotation. The API uses a raw type, so there's nothing else you can do.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!