

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 languages -
objectin 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.
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
This article is licensed under the GNU Free Documentation License.
Last updated on Monday July 21, 2008 at 08:40:55 PDT (GMT -0700)
View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation
Copyright © 2008, Dictionary.com, LLC. All rights reserved.











