43rd: Scala type variable bounds code combat and its application in Spark source parsing

Source: Internet
Author: User
Tags comparable

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.