What's the difference between A<:B and +B in Scala?

后端 未结 4 1540
挽巷
挽巷 2021-01-29 18:20

What\'s the difference between

[A <: B]

and

[+B]

in Scala?

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 18:33

    for my Understanding:


    The first is a parameter type bound, there a upper and lower typebounds in our case its a "type parameter A that is a subtype of B (or B itself).


    The second is a Variance Annotation for a class defintion, in our case a covariance subclassing of B


    Scala: + Java: ? extends T Covariant subclassing

    Scala: - Java: ? super T Contravariant subclassing

提交回复
热议问题