[英]Traverse JavaFileObjects enters into infinite loop
I'm trying to use java compiler api. 我正在尝试使用Java编译器api。 First I've got "mytest.java" which runs well. 首先,我有运行良好的“ mytest.java”。 Then I have this code: 然后我有这段代码:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
String[] as = new String[]{"mytest.java"};
List<String> list = Arrays.asList(as);
Iterable fileObjects = fileManager.getJavaFileObjectsFromStrings(list);
for (Iterator it = fileObjects.iterator(); it.hasNext(); ) {
//RegularFileObject str = (RegularFileObject) it.next();
System.out.println("for loop");
}
(1) I expected that the for loop will be able to iterate all JavaFileObjects. (1)我希望for循环能够迭代所有JavaFileObjects。 In my case, it has only one file, right? 就我而言,它只有一个文件,对吗? But running the program, it prints a lot of "for loop" without stop. 但是运行该程序,它会不停地打印很多“ for循环”。 I expect it's printed only once 我希望它只印一次
So what's wrong here? 那这怎么了?
(2) RegularFileObject is not a public class, so how can I visit the content of these file objects? (2)RegularFileObject不是公共类,那么如何访问这些文件对象的内容?
Thanks. 谢谢。
迭代器“ it”不会在for循环中更新/增加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.