Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Lesson 45: practice of Context Bounds Code in Scala and its Application in Spark Source Code Analysis

Shulou Source: shulou.com Published: 2022-06-03 04:32:47 11月15日 Update

Like view bounds, context bounds (context definition) is also a grammatical sugar for implicit parameters.

The way we use view bounds is written as follows:

Class Pairs [T = 0) first else second}}

If we use implicit conversion, we can change it to the following

Class Pairs_ implied [T] (first: t second implicit ordered) {def bigger (implicit ordered: Ordering [T]) = {if (ordered.compare (first, second) > 0) first else second}}

Scala provides the Context Bounds method, which is written as follows:

Class Pairs_Context_ boundaries [T: Ordering] (first: TJE second def bigger T) {def bigger (implicit ordered: Ordering [T]) = {if (ordered.compare (first, second) > 0) first else second}}

Tags: Writing up and down context parameters methods syntax code practice source code application Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Xiaomi Linux macOS