是否有人可以幫助確定哪些是與下面的代碼的問題......爲什麼是有問題編制的變量「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