In object-oriented Computer programming languages, RTTI stands for RunTime Type Information. This means that at runtime (as opposed to when compiling the program), information is available to the program about the types of objects that are being manipulated by other objects.

Some level of RTTI is found in all object-oriented programming languages that I have looked at.

RTTI can be fairly simple, e.g. simply a couple of virtual methods that give objects the ability for an object to emit their class name, and answer queries such as "Is the object of this type or a subtype thereof", and "does the object support this interface".

This type information can be used to determine at runtime if a typecast is legitimate. With built-in typecasts, an exception is typically thrown if it is not a legitimate cast. For instance C++'s dynamic_cast operator works this way, as does Delphi's as operator. Both Java and C# provide cast operators using C-style syntax, which also work this way. C# also provides an as operator, which happily returns a nil if the object is not of the requested type.

Some RTTI is available in C++, however in more recently-designed languages such as Java and C#, RTTI extends to comprehensive metadata, i.e. a complete list of methods and data upon an object, and the ability to access public data and invoke public methods on an object without knowing all about them at compile-time. This is sometimes known as Dynamic binding or late binding, though it is an even later kind of binding than simply looking up the right entry in a virtual method table by numeric index. Looking through this data is sometimes called introspection.

In COM, interfaces descended from the IUnknown interface provide basic RTTI, and those descended from the IDispatch interface support late binding.

In Delphi, published properties have detailed RTTI. That's what makes them published, not just public. Other methods and properties do not.

Objective-C provides more RTTI than C++, allowing not only queries on types, using the -class, -isMemberOfClass, -isKindOf and –conformsToProtocol, but also querying if an object understands a particular message (i.e. implements a particular method) using -respondsTo.

Log in or register to write something here or to contact authors.