【发布时间】:2016-10-30 08:39:12
【问题描述】:
def getManifest[T : Manifest] = implicitly[Manifest[T]]
class A[T]
object A {
def apply[T] = new A[T]
}
def getA[T : A] = implicitly[A[T]]
val m = getManifest[Int]
//res0: Manifest[Int] = Int
val a = getA[Int]
//<console>:14: error: could not find implicit value for evidence parameter of type A[Int]
即使上下文中没有隐式变量
通过调用getManifest[Int],Manifest[Int] 类型的m 被隐式捕获
但是我的自定义类 A,getA[Int] 发出错误
因为cotext中没有隐式变量。
A类和Manifest有什么区别
Scala 编译器是否知道 Manifest 并做一些魔术?
比如,为 Manifest 创建一些隐式变量
【问题讨论】: