Topic summary

Top type

Extracted from the Wikipedia article Any type.

Other languages

The top type is used as a generic type, more so in languages without parametric polymorphism. For example, before the introduction of generics to Java in Java 5, collection classes in the Java standard library (excluding Java arrays) held references of type java.lang.Object. In this way, any non-intrinsic type could be inserted into a collection. The top type is also often used to hold objects of unknown type. Java supports "wildcard type parameters", represented by ?. For instance, List<?> denotes a list that can hold any type (but not null). Wildcards can be bounded, List<?extendsT> and List<?superT> denote a list that can hold any type that inherits from/is an ancestor class of (respectively) type T (including T itself). Wildcards however cannot simultaneously have both upper and lower bounds.