Definition
Subtype Relation
Let and be types. is called subtype of , denoted as , if anywhere where an expression of type is expected, an expression of type can be safely used (Liskov Substitution Principle).
The subtype relation forms a partial order.
Language-Specific
Java
Let be reference types.
- (reflexive)
- (transitive)
- (antisymmetric)
Thus, the subtype relation is a partial order.
- Every dynamic type is a Java class
- is not an object of , whereby the compiler accepts it
Assumption: Method comments in and are compatible, with :
- Comment in explains the same method as comment in
- Comment in can be more concrete
- Comment in can be more abstract
Object-Oriented Perspective
A type is subtype of type iff:
-
- i.e. type of is subtype of type
-
- i.e. type of is equivalent to type
-
- parameter count and types are equal
- parameter types are compatible
- result type of is subtype of result type in
- does not throw more exceptions than