Runtime type information

from Wikipedia, the free encyclopedia

RTTI stands as an abbreviation for Runtime Type Information and is a term from software development and a component of various programming languages .

RTTI makes it possible to determine the type of an object at runtime . In this way, a program can determine during its execution to which specific class an object belongs to which a specific reference points. Without this mechanism, the program would only “know” at this point that an instance of some class is referenced that is derived from the base class. With this mechanism it “knows” which class the referenced object belongs to.

While RTTI is a very simple mechanism that usually only supplies the name of the specific class, more modern programming languages ​​have the mechanism of reflection , which also enables information about other properties of a class to be determined at runtime, e.g. B. the names and signatures of their methods.

example

So be z. B. is given a reference to an example of the base class " Geschäftspartner", of which two specific subclasses " Kunde" and " Lieferant" are defined. With type information at runtime, the program can find out whether a certain business partner is a customer or a supplier.

particularities

  • In Java , the type information is provided at runtime by the method " getClass", which returns a reference to a so-called class object, which among other things knows the name of the specific class.
  • One of the is operators is available in Object Pascal . You can also query the ClassInfo, ClassType and ClassName of an object.