Is it right that this code
List<Integer> test2 = new ArrayList<Integer>();
test2.add(343);
int x2 = test2.get(0);
in compile time will be converted to this
List test = new ArrayList();
test.add(343);
int x = (Integer)test.get(0);
Something similar with autoboxing…
Let’s try. Take this class with two methods that do absolutely the same thing with and without generics and autoboxing:
Here’s the byte code:
I don’t see any obvious difference between the generic and the non-generic version, in fact here’s the
diffresult for the two methods:As you can see, the only difference is in the line numbers and the local variable table.