Black monkey house: Scala chapter (type parameter) points

(1) type, characteristics, functions and methods can have type parameters

(2) the type of the parameter is placed after the name, in square brackets

Syntax (3) of the type defined as T <: UpperBound, T>: LowerBound, T: ContextBound

(4) we can use the type of constraint to a constraint method, such as (implicit ev: T <: <UpperBound)

(5) + T (covariant) to represent a consistent sub-type relationship between the amount of generic class parameter T direction, or with -T (inverter) is represented in the opposite direction

(6) adapted to the covariant parameter indicates the type of output, such as immutable elements in the collection

(7) applied to the inverter input parameter indicates the type of function parameters such as

Reproduced in: https: //www.jianshu.com/p/9600d0071d03

Guess you like

Origin blog.csdn.net/weixin_33859231/article/details/91182521