- Top type
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 aresubtype s of top. It is in contrast with thebottom type , or the "universal subtype", which is the type containing no members at all.upport in programming languages
Several typed programming languages provide explicit support for the top type.
Most
object oriented programming languages include a universalbase class :
* InGlib , the base class is
.Gobject
*Object
inSmalltalk , Java,JavaScript , Ruby, and some others. In Java, it is frequently prefixed written with a package designation, as Javadoc:SE|package=java. _ja. Object. Note also thatObject
is not a supertype of the primitive types in Java.
*[http://msdn.microsoft.com/en-us/library/system.object.aspx System.Object]
in C#,Visual Basic .NET and other.NET Framework languages
*object
in Python since the [http://www.python.org/download/releases/2.2.3/descrintro/ type/class unification] in Version 2.2.
*GENERAL
in Eiffel.
*t
inCommon Lisp and many other Lisp dialects.
*Object
inObjective-C . InOpenStep and Cocoa, which are the most popular frameworks based on the language, it is NSObject.
*UNIVERSAL
inPerl 5.
*Variant
inVisual Basic up to version 6C++ 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 thevoid type itself is not the universal type but theunit 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 language s, the top type is anabstract type --it contains no elements which are not elements of some (declared) subtype. Java is an exception: the phrasenew 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 inJava 5 , collection classes in the Java library (excluding Java arrays) held references of typeObject
; 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.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 fromvoid *
in C++ cannot be done in a "safe" manner, where failed downcasts are detected by the language runtime.References
*
External links
* [http://www.c2.com/cgi/wiki?TopType c2.com: Top type]
Wikimedia Foundation. 2010.