Generic types (types with type parameters) have been introduced into Java with language version 1.5. If type parameters are specified for a class
or method, it is still possible to ignore them to keep backward compatibility with older code, which is called the raw type of the class or
interface.
Using raw type expressions is highly discouraged because the compiler cannot perform static type checking on them. This means that the compiler
will not report typing errors about them at compile time, but a ClassCastException
will be thrown during runtime.
In Java 1.5, generics were also added to the Java collections API, and the data structures in java.util
, such as List
,
Set
, or Map
, now feature type parameters. Collections.EMPTY_LIST
, Collections.EMPTY_SET
, and
Collections.EMPTY_MAP
are relics from before generics, and they return raw lists, sets, or maps, with the limitations mentioned
above.