Skew and resistance of generic Interfaces
1. Glossary
(1) covariant: the object of the parent class is replaced by a subclass.
(2) Resistance to changes: the subclass object is replaced by the parent class.
For example, if the parameters of the method are covariant, the return value is variable-resistant.
2. Coordination and resistance of generic Interfaces
(1) covariant: IDemo <out T >== "IDemo <out ParentT>
Generic Type T can only be used as the return value of methods or attributes in IDemo
(2) Resistance to changes: IDemo <in ParentT >== "IDemo <in T>
Generic Type T can only be used as a parameter of the method in IDemo
Simply put, we can understand from the word out and in: out indicates that the generic type can only be returned, and in indicates that the generic type can only be used as input.
3. Why?
Changing from T to ParentT is type-safe, and vice versa.