typesubtype
Typesubtype, commonly referred to simply as subtyping, is a relationship between types in a type system. If type A is a subtype of type B, values of A can be used wherever a value of B is expected without causing type errors. This containment means every value of A is also a value of B, but B may have additional values that A does not possess.
In programming languages with inheritance, subtyping often comes from class hierarchies: if A extends B, then
Formal rules of subtyping can vary. A common notation is A ≤ B to denote that A is
When parameterized types are involved, subtyping becomes more nuanced. Variance explains how subtyping propagates through type
Subtyping is central to type safety and language design. It supports flexible interfaces and code reuse while