scala "←" "<-"

程序里看到"←"符号

(for {
            routee ← valueHolder.routee
          } yield routee).toVector

找遍scala的操作符表都没找到,回头才发现,原来这是一个for循环的条件,只不过在scala的函数中,小括号和大括号是一样的。

另外"←" "<-"这两个符号也是一样的效果。

这里类似赋值的意思。我们可以写几个测试下:

object ForDemo {
  def main(args: Array[String]): Unit ={
    var a = 0
//    for(a <- 1 until 10){
//      println("Value of a :" + a)
//    }

    for { a ← 1 until 2}{
      println("Value of a :" + a)
    }
  }

}

没毛病。

输出:

Value of a :1

原文地址:https://www.cnblogs.com/guazi/p/7058298.html