Lesson 45: practice of Context Bounds Code in Scala and its Application in Spark Source Code Analysis
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}}