是否有人可以帮助确定哪些是与下面的代码的问题......为什么是有问题编制的变量“i $”为什么变量的范围有问题?
下面是代码....
private void handlePendingFilesForPreviousCheckpoints(Map<Long, List<String>> pendingFilesPerCheckpoint) {
LOG.debug("Moving pending files to final location on restore.");
Set<Long> pastCheckpointIds = pendingFilesPerCheckpoint.keySet();
Iterator i$ = pastCheckpointIds.iterator();
while(i$.hasNext()) {
Long pastCheckpointId = (Long)i$.next();
Iterator i$ = ((List)pendingFilesPerCheckpoint.get(pastCheckpointId)).iterator();
while(i$.hasNext()) {
String filename = (String)i$.next();
Path finalPath = new Path(filename);
Path pendingPath = this.getPendingPathFor(finalPath);
try {
if(this.fs.exists(pendingPath)) {
LOG.debug("Restoring BucketingSink State: Moving pending file {} to final location after complete checkpoint {}.", pendingPath, pastCheckpointId);
this.fs.rename(pendingPath, finalPath);
}
} catch (IOException var10) {
LOG.error("Restoring BucketingSink State: Error while renaming pending file {} to final path {}: {}", new Object[]{pendingPath, finalPath, var10});
throw new RuntimeException("Error while renaming pending file " + pendingPath + " to final path " + finalPath, var10);
}
}
}
}
即使i$
的大括号...它说,该变量i$
在范围已经定义第二次内部定义....
有人可以帮我解决这个问题......并且明白什么是在上面的代码中,变量i $是错误的。
非常感谢。
*“帮我解决这个问题”*将内部变量命名为别的东西。什么是不明显的? – Andreas
为什么你使用迭代器while循环,而不是更容易增强'for'循环?例如。 (longCheckCheckpointId:pendingFilesPerCheckpoint.keySet()){...}'---另外,不要使用* raw *泛型,即不要使用'Iterator',但在外层循环中使用'Iterator' 。 –
Andreas
@Andreas当然,但是,正如我从其他类复制这块代码..在那里我观察员没有问题..但为什么它在我的课上创建问题。你可以在这方面分享一些意见。非常感谢。 – Raja