Our goal is to type check methods in a class in such a way that they are guaranteed to be type-safe no matter how they are inherited. We saw in the previous section that we avoid typing problems if we replace the types of methods by subtypes in subclasses. The definition of matching captures exactly this change in method types between object types.
We say that object type matches object type , written , iff for each method of there is a corresponding method of such that . Put slightly differently,
It follows that if is a subclass of then . We will see below that matching is weaker than subtyping. The difference between this and our earlier definition of subtyping for objects (which looked identical) is the presence of the keyword MyType.One important point here: In determining whether two object types match in the above definition, we determine if without making any assumption on the meaning of MyType. As a result the two types will certainly be subtypes in any particular context where MyType stands for some fixed type.