大数据学习——scala函数与方法

package com

/**
  * Created by Administrator on 2019/4/8.
  */
object TestMap {


  def ttt(f: Int => Int): Unit = {
    val r = f(10)
    println(r)
  }

  val f0 = (x: Int) => x * x


  def m0(x: Int): Int = {

    x * 11
  }

  def main(args: Array[String]) {
    //    val arr=Array(1,2,3,4,5,6,7,8,9)
    //    val r=arr.map(x => x * 10)
    //    println(r.toBuffer)
    ttt(f0)
    ttt(m0 _)
    ttt(m0) //把一个方法的名字传到函数里面,其实就是将方法转换成函数传到方法里边,利用了下划线
    ttt((x => m0(x)))
    ttt(x => m0(x))
  }
}

 

posted on 2019-05-31 14:43  o_0的园子  阅读(267)  评论(0编辑  收藏  举报