The top type in type theory, commonly abbreviated as top or by the down tack symbol (⊤) is the universal type--that type which contains every possible object in the type system of interest. The top type is sometimes called the universal supertype as all other types in any given type system are subtypes of top. It is in contrast with the bottom type, or the universal subtype, which is the type containing no members at all.
Support in programming languages
Several typed programming languages provide explicit support for the top type.
Most object oriented programming languages include a universal base class:
- In Glib, the base class is
Gobject. Objectin Smalltalk, Java, JavaScript, Ruby, and some others. In Java, it is frequently prefixed written with a package designation, asjava.lang.Object. Note also thatObjectis not a supertype of the primitive types in Java.System.Objectin C#, Visual Basic .NET and other .NET Framework languagesobjectin Python since the type/class unification in Version 2.2.GENERALin Eiffel.tin Common Lisp and many other Lisp dialects.Objectin Objective-C. In OpenStep and Cocoa, which are the most popular frameworks based on the language, it is NSObject.UNIVERSALin Perl 5.Variantin Visual Basic up to version 6
C++ is unusual among OO languages in that it does not have a universal supertype. The "pointer to void" type can accept a pointer to any object, even though the void type itself is not the universal type but the unit type.
Non-OO languages usually do not have a universal supertype (or support subtype polymorphism at all). Common Lisp is an exception in that its built-in types form a type hierarchy even when its object system CLOS is not used.
In most programming languages, the top type is an abstract type--it contains no elements which are not elements of some (declared) subtype. Java is an exception: the phrase new Object() is perfectly legal Java.
The top type is used as a generic type, particularly in languages without parametric polymorphism. For example, prior to the introduction of generics in Java 5, collection classes in the Java library (excluding Java arrays) held references of type Object; in this way any non-intrinsic type could be inserted into a collection. The top type is also frequently used to hold objects of unknown type.
In languages with a structural type system, the top type is the empty structure. For example, objects in OCaml are structurally typed; the empty object type (the type of objects with no methods), "< >", is the top type of object types. Any OCaml object can be explicitly upcasted to this type, although the result would be pretty useless.
The top type may also be seen as the implied type of non-statically typed languages. Languages with runtime typing often provide downcasting (or type refinement) to allow the programmer to discover a more specific type for an object at run-time. Note that downcasting from void * in C++ cannot be done in a "safe" manner, where failed downcasts are detected by the language runtime.
References
External links
No comments have been added.





