There is only one ArrayList class, but it supports generics, which means you can annotate it with a type. However, this is not necessary (mainly for backward compatibility), so you can also continue to use the raw type (but this is not recommended).
Note that Java generators occur only for the compiler, and at run time, the ArrayList instance itself does not know which generic type you assigned to it. This means that it works exactly the same as internally if you annotate it or not.
Unlike arrays, there are no new separate classes for shared collections. Thus, although there is a different class for Integer[] than for String[] (or for Integer[][] ), the class for ArrayList<String> is the same as for ArrayList<Integer> (and ArrayList<?> and ArrayList and ArrayList<List<Integer>> ).
And also, unlike arrays, there is nothing special about generics for use by collections (although this remains their most popular application). The same mechanism can be used for completely different things, for example Callable.
source share