我有一个对象,我需要将其类传递给一个带有
java.lang.Class的注释,例如:
public @interface PrepareForTest { Class<?>[] value() } object MyObject @PrepareForTest(Array(?????)) class MySpec ...
我试过了:
@PrepareForTest(Array(classOf[MyObject])) // error: not found: type MyObject @PrepareForTest(Array(MyObject)) // error: type mismatch // found: MyObject.type (with underlying type object MyObject // required: java.lang.Class[_] @PrepareForTest(Array(classOf[MyObject.type])) // error: class type required by MyObject.type found
不知道还有什么可以尝试.
解决方法
classOf [MyObject $]不起作用,因为没有名为MyObject $的类型.
事实上,问题确实出现过,并没有简单的解决方案.请参阅https://lampsvn.epfl.ch/trac/scala/ticket/2453#comment:5的讨论