与 Scala 中的 class 同名的对象中隐式函数的作用域
Scope of implicit functions in objects with the same name as the class in scala
问题很简单:在Scala中,对象A的隐式函数定义是否在classA的作用域内?或者我是否必须显式使用 import A._
才能访问隐式函数?
The question is simple: in Scala, are the implicit function definitions of object A in the scope of class A?
不,您必须导入它们(与 object A
的非隐式成员相同)。但是,当然,如果范围内有 none,则始终会在伴随对象中搜索 从或到 A
的任何隐式转换。
问题很简单:在Scala中,对象A的隐式函数定义是否在classA的作用域内?或者我是否必须显式使用 import A._
才能访问隐式函数?
The question is simple: in Scala, are the implicit function definitions of object A in the scope of class A?
不,您必须导入它们(与 object A
的非隐式成员相同)。但是,当然,如果范围内有 none,则始终会在伴随对象中搜索 从或到 A
的任何隐式转换。