4 ms·
> How does the compiler know that the implementing class can be used where the interface is required Structural typing. The instance does not assert to the co
by msbarnett 7y ago
> How does the compiler know that the implementing class can be used where the interface is required
Structural typing.
The instance does not assert to the compiler an exhaustive list of all interfaces it claims to conform to; instead, the compiler determines, during compilation, whether the concrete instance being passed meets the requirements of a declared interface. The net result is that an implementation need not have known about an interface when it was written; it need merely match the interface’s requirements when called upon to do so.
It is, effectively, statically enforced duck typing.