我正在阅读Spring Boot的源代码。我在阅读SpringFactoriesLoader.loadFactoryNames
时发现一个问题。 URLClassPath.getResources
返回 Enumeration<Resource>
的执行情况,但该值有额外的两个字段 name
和check
。那么,什么时候将这两个字段添加到返回值中呢?
public Enumeration<Resource> getResources(final String var1, final boolean var2) {
return new Enumeration<Resource>() {
private int index = 0;
private int[] cache = URLClassPath.this.getLookupCache(var1);
private Resource res = null;
private boolean next() {
if (this.res != null) {
return true;
} else {
do {
URLClassPath.Loader var1x;
if ((var1x = URLClassPath.this.getNextLoader(this.cache, this.index++)) == null) {
return false;
}
this.res = var1x.getResource(var1, var2);
} while(this.res == null);
return true;
}
}
public boolean hasMoreElements() {
return this.next();
}
public Resource nextElement() {
if (!this.next()) {
throw new NoSuchElementException();
} else {
Resource var1x = this.res;
this.res = null;
return var1x;
}
}
};
}
我使用Intellij调试程序,结果是
最佳答案
在本例中,Result 实例是一个匿名类,它捕获 getResources
参数 (final String var1, Final boolean var2)
的值。
关于java - 为什么URLClassPath的getResources函数的返回值对象多了两个字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55354378/