Lesson 43: practice of type variable Bounds code in Scala and its application in Spark source code analysis
Definition of type variables:
The upper bound of the type variable and the lower bound of the type variable.
The upper bound is that the type must be a subclass that defines the type, as shown in the following example:
Package com.dt.scala.type_parameterization// We need to define a generic class Pair. There is a bigger method in the generic class to compare the passed parameter / / at this time the generic type must be a subclass of Comparable We can use the: symbol to qualify the next class Pair_Lower_ boundaries [T] (first: t second def replace T) {def replace [R >: t] (newFirst: r) = {/ / R must be the parent of T new Pair_Lower_Bounds (newFirst,second)}}