Compatible Only Interface

no-email (Damien Seguy), Damien Seguy
Fri, 02 Aug 2024 00:00:00 +0000

Interfaces are contracts that defines methods signatures, which implmenting class have to implements.
One lesser known fact is that the implementation only has to be compatible with the interface, there is no need to be identical. It is the same behavior than in class inheritence.
This explains that the following code is valid, both with argument contra-variance and return type variance.
Note that the names of the parameters are completely free to be changed at will, yet it is not recommended.