Skip to content
subtyping
EntityQ2713292· pop 11· linked from 167 articles

Also known as subtype polymorphism, inclusion polymorphism

In programming language theory, subtyping (also called subtype polymorphism or inclusion polymorphism) is a form of type polymorphism. A subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, meaning that program elements (typically subroutines or functions), written to operate on elements of the supertype, can also operate on elements of the subtype.

Wikidata facts

Show 1 more fact
Sources (3)

via Wikidata · CC0

~20 min read

Article

16 sections
Contents
  • Origins
  • Examples
  • C++
  • Python
  • Java
  • Subsumption
  • Subtyping schemes
  • Record types
  • Width and depth subtyping
  • Function types
  • Relationship with inheritance
  • Coercions
  • See also
  • Notes
  • References
  • Further reading

In programming language theory, subtyping (also called subtype polymorphism or inclusion polymorphism) is a form of type polymorphism. A subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, meaning that program elements (typically subroutines or functions), written to operate on elements of the supertype, can also operate on elements of the subtype.

If S is a subtype of T, the subtyping relation (written as ,  , or   ) means that any term of type S can safely be used in any context where a term of type T is expected. The precise semantics of subtyping here crucially depends on the particulars of how "safely be used" and "any context" are defined by a given type formalism or programming language. The type system of a programming language essentially defines its own subtyping relation, which may well be trivial, should the language support no (or very little) conversion mechanisms.

Gallery (2)

Available in 11 languages

via Wikidata sitelinks · CC0

Connections

Categories