Monday, July 22

What is covarient and invarient

Covarient simply means if x is subtype of Y then x[] will also be sub type of Y[]. Arrays are covarient
As string is subtype of Object So

String[] is subtype of Object[]


Invarient simply means irrespective of X being subtype of Y or not , List<X> will not be subType ofList<Y>.

generics are invarient

Although string is subtype of Object So

List<String> is not subtype of List<Object>

No comments:

Post a Comment