markdown [Java中的协变和逆变] #java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown [Java中的协变和逆变] #java相关的知识,希望对你有一定的参考价值。

Arrays are covariant but generics aren'. The following is the explanation behind using wildcard `<? extends T>` in generics.

At heart, these terms describe how the subtype relation is affected by type transformations. That is, if A and B are types, f is a type transformation, and ≤ the subtype relation (i.e. A ≤ B means that A is a subtype of B), we have

f is covariant if A ≤ B implies that f(A) ≤ f(B)
f is contravariant if A ≤ B implies that f(B) ≤ f(A)
f is invariant if neither of the above holds

Ref
- https://dzone.com/articles/covariance-and-contravariance
- https://stackoverflow.com/a/2501513/1749223
- https://stackoverflow.com/a/8482091/1749223

以上是关于markdown [Java中的协变和逆变] #java的主要内容,如果未能解决你的问题,请参考以下文章

Java泛型中的协变和逆变

Typescript中的协变和逆变

Typescript中的协变和逆变

Typescript中的协变和逆变

Typescript中的协变和逆变

了解 C# 中的协变和逆变接口