Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
scala 类型绑定符号方向是否存在差异,因为[B <: A]与 相同[A >: B]?
[B <: A]
[A >: B]
B <: A表示B的上限为A。这意味着它B可以是类型层次结构中的Nothing任何类型。A
B <: A
B
A
Nothing
A >: B表示它A的下界为B,这意味着它A可以是类型层次结构中从B到的任何东西。Any
A >: B
Any
一般来说,它们的意思不同。每一个都对不同的类型参数施加一个界限。这也不是方差表示法,这些是类型界限。
在这里[B <: A]你声明B了扩展的类型A,在这里[A >: B]你声明了类型A的父类型B。