Invariance of Generic Types
Although Dog is a subtype of Animal, Container<Dog> does not automatically become a subtype of Container<Animal>. This is because in Cangjie, user-defined generic types are invariant at their type parameters.
This design avoids type safety issues. For example, if Array<Dog> could be used as Array<Animal>, you could add a Cat to it, breaking type safety.
There are two ways to solve polymorphism problems: using constraints on generic parameters, or using base type arrays to store different subtypes. The code on the right demonstrates both approaches: the makeSpeak function uses where T <: Animal constraint and can accept any Animal subtype; the speakAll function uses Array<Animal> and can store mixed subtypes.
Note
Built-in tuple types are covariant at their element types, and function types are contravariant at their parameter types and covariant at their return types.