It means that if you have anything that is parameterized, e.g. List<Foo> fooList = new ArrayList<Foo>();
, the Generics information will be erased at runtime. Instead, this is what the JVM will see List fooList = new ArrayList();
.
This is called type erasure. The JVM has no parameterized type information of the List
(in the example) during runtime.
A fix? Since the JVM has no information of the Parameterized type on runtime, there's no way you can do an instanceof
of ArrayList<Foo>
. You can "store" the parameterized type explicitly and do a comparison there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…