给定 class Foo[F[_]]
,如何获取 Class
对象?通常的语法不起作用:
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[_[_]]]
^
最佳答案
啊,对了。留下这个以防有人寻找它:
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
关于scala - classOf[] 表示更高级的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32201216/