News for hackers. Stuff that matters.
Re:Interfaces Generally Belong with Users by msbarnett on Saturday November 23, 2019 @04:52PM (#21616846)
> 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.

There are no comments on this comment yet.