【发布时间】:2017-11-30 19:22:49
【问题描述】:
import com.this.class.Factory;
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Itearate over all @Factory annotated elements
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
...
}
}
这在我在注解处理器中导入注解类时有效。但是动态加载注解类的时候就不行了
Class<?> Factorry = class.forName("com.this.class.Factory")
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Itearate over all @Factory annotated elements
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
...
}
}
使用class.forName()加载类时如何将带注释的Factory.class传递给getElementsAnnotatedWith
【问题讨论】:
-
请提供更多关于“不起作用”的信息
-
无法将工厂解析为类型。这是我看到的编译错误。它正在寻找 Factory.class 文件导入
标签: java class methods reflection