According to this question/answer Any way to obtain a Java class from a Scala (2.10) type tag or symbol?
I should use runtimeClass
to obtain the Class
from a type.
But if I do reflection in Macros I don't have access to runtimeClass
. How can I do?
In macros, you can have a TypeTag
for a class which isn't actually compiled yet and thus doesn't have a Class
object, that's why there is no runtimeClass
. If you want to try anyway (eg because you know the class is from a dependency, not being compiled), I don't know any way other than Class.forName
, as in the question. Of course, you can use runtimeClass
in the generated code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.