• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics type safety  RSS feed

 
Karthik Vijayarajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I was trying out some generics in my code. I understand that i cant get away without a warning if i dont specify the type of the collection in 1.5. This is my code and it gives a warning that reads like "Type safety: The expression of type List needs unchecked conversion to conform to List<Integer>".



Can any of you throw some light on whats happening. Is the warning because the return type of the anonymous inner class is Object and the compiler cannot ensure type safety? Is it still safe to leave the code like this?

Thanks
Karthik
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jdbcTemplate.query does not return a List<Integer> but a List.

Now I don't know this class, but my guess is that all elements in the list are the objects returned by the RowMapper's mapRow method. Since that always returns an Integer (autoboxed int), the elements in the list will be Integers. Therefore it is safe in this case.

Please check out the @SuppressWarnings annotation, especially with parameter "unchecked", if you want these warnings that you are 100% sure of they can be ignored to not appear.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!