1.scala中的<%意识是“view bounds”(视界) ,它比<:的使用范围更广,还能进行隐式转换,是一种语法糖。

下面的两种写法是等效的,在编译之后完全一样。

object Test {

  def main(args: Array[String]) {

  }

  def method1[A<% Int](a:Int): Unit ={

  }

  def method2[A](a:Int)(implicit b:A=>Int): Unit ={

  }

}
View Code

相关文章:

  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-09-13
  • 2021-09-20
猜你喜欢
  • 2021-09-14
  • 2021-06-13
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-07-01
相关资源
相似解决方案