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 ={ } }
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 ={ } }
相关文章: