方法参数是隐式的吗?-使用scala 2.10反射

方法参数是隐式的吗?-使用scala 2.10反射,scala,reflection,scala-2.10,Scala,Reflection,Scala 2.10,给出一个反射方法: scala> val sortMethod = typeOf[::[_]].member(newTermName("sorted")) sortMethod: reflect.runtime.universe.Symbol = method sorted scala> sortMethod.typeSignature res122: reflect.runtime.universe.Type = [B >: A](implicit ord: scala.m

给出一个反射方法:

scala> val sortMethod = typeOf[::[_]].member(newTermName("sorted"))
sortMethod: reflect.runtime.universe.Symbol = method sorted

scala> sortMethod.typeSignature
res122: reflect.runtime.universe.Type = [B >: A](implicit ord: scala.math.Ordering[B])Repr

找出该方法是否具有隐式参数(在scala 2.10-M4+中)的最佳方法是什么?

目前,我认为您不能
isImplicit
was,因此您应该能够在夜间构建或下一个里程碑版本中使用它

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> val sortMethod = typeOf[::[_]].member(newTermName("sorted")).asMethod
sortMethod: reflect.runtime.universe.MethodSymbol = method sorted

scala> sortMethod.params // `params` has been added only a few days ago
res0: List[List[reflect.runtime.universe.Symbol]] = List(List(value ord))

scala> sortMethod.params(0)(0).asTerm.isImplicit
res2: Boolean = true

scala> sortMethod.params(0)(0) hasFlag Flag.IMPLICIT
res3: Boolean = true
如果你问我喜欢哪种方式,我建议使用
isXXX
方法。首先,这是一种一致的测试方法,因为只有十几个左右的公共标志,但要测试的东西要多得多(例如,
isStable
isSynthetic
)。其次,标志比看起来更复杂(例如,几个标志名称可能对应于标志掩码中的同一位),因此
isXXX
方法提供了更好的封装