2015-08-25 46 views
2

鉴于class Foo[F[_]],如何获得Class对象?常用的语法不起作用:classOf []用于更高级别的类型

scala> classOf[Foo[_]] 
<console>:9: error: _$1 takes no type parameters, expected: one 
       classOf[Foo[_]] 
         ^

也不对

scala> classOf[Foo[_[_]]] 
<console>:9: error: _$1 does not take type parameters 
       classOf[Foo[_[_]]] 
         ^

回答

3

啊,对。离开这个万一有人查找它:

scala> classOf[Foo[F] forSome { type F[_] }] 
warning: there were 1 feature warning(s); re-run with -feature for details 
res0: Class[Foo[_[_] <: Any]] = class Foo 
+0

这是你如何遇到麻烦,因为Scala使用相同的语法一个很好的例子'F [_]'有时意味着更高kinded型,有时一个存在型。 –