When using generic Lists, I get compiler warnings. If I want to have a generic return type, which of the following two options should be done? (Note the use of a cast in the second option.)
Also, what's the disadvantage to not using @SuppressWarnings? It seems like it's optional...
@DataModel @SuppressWarnings("unchecked") public List<Something> getSomethings() { return myQuery.getResultList(); }
Type safety: The expression of type List needs unchecked conversion to conform to List<Something>
@DataModel @SuppressWarnings("unchecked") public List<Something> getSomethings() { return (List<Something>) myQuery.getResultList(); }
Type safety: The cast from List to List<Something> is actually checking against the erased type List
This is not a seam question at all, is it?
Anyway, read the following pdf, especially the sections about type erasure.
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf