does Java type erasure erase my generic type?

前端 未结 5 1567
执念已碎
执念已碎 2020-12-25 07:53

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.

5条回答
  •  眼角桃花
    2020-12-25 08:44

    Type info will be erased from here

     integerList = new ArrayList(); 
    

    in the bytecode it will be equivalent to

    integerList = new ArrayList(); 
    

    and there is no chance to know in runtime from integerList object what was its compile time type.

提交回复
热议问题