I have an object and I need to pass its class to an annotation that takes java.lang.Class, eg:
public @interface PrepareForTest {
Class<?>[] value()
}
object MyObject
@PrepareForTest(Array(?????))
class MySpec ...
I’ve tried:
@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
Not sure what else to try.
classOf[MyObject$]does not work because there is no type calledMyObject$.In fact, the issue did come up before and there is no easy solution. See the discussion on https://lampsvn.epfl.ch/trac/scala/ticket/2453#comment:5