Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Lesson 43: practice of type variable Bounds code in Scala and its application in Spark source code analysis

Shulou Source: shulou.com Published: 2022-06-03 05:39:32 09月25日 Update

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)}}

Tags: Types variables upper bounds subclasses symbols lower bounds parameters that is methods examples code actual combat source code applications Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Shulou Technology Linux NVidia