The definition of a type variable:
The upper bound of the type variable, the lower bound of the type variable.
The upper bound is the subclass of the type that must be defined, see the following example:
Package com.dt.scala.type_parameterization//We need to define a generic class pair with a bigger method in the generic class that compares the arguments passed in//at which time the generic type must be a subclass of comparable. We can use <: Symbol to qualify incoming type class pair[t <: comparable[t]] (first:t,second:t) {def bigger ={if (First.compareto (second) >=0) First else second}}object type_variables_bounds {def main (args:array[string]): Unit = {val pair = new Pa IR ("Spark", "Hadoop") println (Pair.bigger)}}
Next: Type must be a parent of a defined type
We use the: symbol to do the next qualifying class Pair_lower_bounds[t] (first:t,second:t) {def replace[r;: t] (newfirst:r) = {//R must be the parent of T New Pair_lower_bounds (Newfirst,second)}}
This article is from the "Ding Dong" blog, please be sure to keep this source http://lqding.blog.51cto.com/9123978/1742149
43rd: Scala type variable bounds code combat and its application in Spark source parsing