首页 > 其他 > 详细

=>

时间:2020-10-27 13:53:30      阅读:24      评论:0      收藏:0      [点我收藏+]

使用场景

package graphx

object case03 {
  def main(args: Array[String]): Unit = {

    //TODO 1.表示函数的返回类型


    def double(x:Int):Int=x*2

    //定义一个函数变量
    var x:(Int)=>Int=double
    println(x(2))


    //TODO 匿名函数 左边是参数 右边是函数实现体 (x: Int)=>{}
    var xx = (x:Int)=> x+1



    //TODO case语句
    val booleans = List(true,false)
    for(bool <- booleans){
      bool match{
        case true=>println("heads")
        case false=>println("tails")
        case _=>println("no")
      }
    }

    //TODO By-Name Parameters(传名参数),传名参数在函数调用前表达式不会被求值,而是会被包裹成一个匿名函数作为函数参数传递下去,
    def doubles(x: =>Int)={
      println(x)
      x*2
    }

    println(doubles(3))

    def f(x:Int):Int={
      x
    }
    println("********************")
    println(doubles(f(3)))






  }



}

 

=>

原文:https://www.cnblogs.com/hapyygril/p/13884090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!