Priyanka Sumanam wrote:I have the below generics code
List<Object> resultset = queryObj.list();
//logic to do with recordss
at the first line of this code , i.e., queryObj.list(); I get the warning
Type safety: The expression of type List needs unchecked conversion to conform to List<Object>
could any one please help on getting rid of this warning?
Joe Areeda wrote:
The problem is queryObject.list() is returning a List not List<Object>. The way to deal with it properly is to change the called method (IMHO) but there are still plenty of code in class libraries out there that don't implement generics.
That's what I believe.
Jaikiran Pai wrote:
I don't know, but probably that API was written before generics were introduced?
Rob Spoor wrote:Unfortunately, sometimes you just have to suppress warnings, because the generic type is no longer available at runtime. If it were a cast to List<Integer> would fail for a List<String>. But you probably suppress warnings quite a bit already, you just don't know it because the suppression occurs in other APIs.