我有以下代码:
Reflections reflections = new Reflections("com.mypackage.cmds");
Set<Class<? extends Command>> commandClasses = reflections.getSubTypesOf(Command.class);
Run Code Online (Sandbox Code Playgroud)
它的作用是存储在com.mypackage.cmds包中的Command类的所有类后代.
现在我想做的是迭代或遍历返回的集合,因此每个类都加载调用Class.fromName方法.我怎样才能做到这一点?
非常感谢提前,
你使用标准的for-each循环来做到这一点:
for (Class clazz: commandClasses) {
// operate on clazz
}
Run Code Online (Sandbox Code Playgroud)
这适用于实现该Iterator
接口的任何Collection .
归档时间: |
|
查看次数: |
2812 次 |
最近记录: |