does Java type erasure erase my generic type?
bytecode, generics, java, jvm, type-erasure
Solution
Some Generic type information is stored in `Signature` attributes . Refer JLS 4.8 and 4.6 and JVM spec 4.3.4. Read here:
Probably the most common complaint about generics in Java is that they are not reified - there is not a way to know at runtime that a `List<String>` is any different from a `List<Long>`. I've gotten so used to this that I was quite surprised to run across Neil Gafter's work on Super Type Tokens. It turns out that while the JVM will not track the actual type arguments for instances of a generic class, it does track the actual type arguments for subclasses of generic classes. In other words, while a new `ArrayList<String>()` is really just a new `ArrayList()` at runtime, if a class extends `ArrayList<String>`, then the JVM knows that `String` is the actual type argument for `List`'s type parameter.
and Neal Gafter's blog.
Problem
I've thought java erasure wipes generic types out in compile time however when i test it by myself i realized there are some information about generic types in Bytecode. here is my test : i wrote 2 classes: ``` import java.util.*; public class Test { List integerList; } ``` and ``` import java.util.*; public class Test { List<Integer> integerList; } ``` i compiled both classes and somewhere in generic class i saw this line ``` integerList{blah blah}Ljava/util/List;{blah blah} Signature{blah blah}%Ljava/util/List<Ljava/lang/Integer;>;{blah blah}<init> ``` in non generic class : ``` integerList{blah blah}Ljava/util/List;{blah blah}<init> ``` so obviously i have generic information inside bytecode so what is this erasure thing ??