ArrayList<Long>
Hi,
I have
ArrayList<Long> serialId = (ArrayList<Long>)request.getSession().getAttribute("serialId");
which is cool but I receive this warning (from eclipse ide):
Type safety: The cast from Object to ArrayList<Long> is actually checking against the erased type ArrayList
What's the meaning of this warning?
thanks in advance,
Manuel Leiria
It's telling you how generics really work. That cast happens at runtime, right? But the type parameters are only kept around through compile time. For example, this code runs (after compiling with a warning) even though the method isn't passed a list of Integers:
import java.util.*;
public class Demo {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("alpha");
list.add("beta");
System.out.println(test(list));
}
static int test(Object object) {
List<Integer> wrong = (List<Integer>) object;
return wrong.size();
}
}