Abstract
- Generic type information is removed or “erased” at runtime. This means that while you can use types like
List<Integer>
orList<String>
at compile-time, the actual type information aboutInteger
orString
is not preserved at runtime. At runtime, bothList<Integer>
andList<String>
will be treated asList
with the default type, which in Java isObject
Then what is the point of generic type information?
IIt is used by the compiler to perform type checking. The compiler will then generate code with proper type casting enforced.