我有下面的定時器代碼,並且根據run方法的執行情況判斷它是否成功,我想返回一個布爾值。在run方法中調用一個定時器的方法返回一個值我需要用上游
但是,我收到錯誤消息: 在封閉範圍內定義的局部變量必須是最終的或有效的最終結果。
如何解決此問題以實現我想要的功能? 下面是代碼:
private boolean getSwitchesOnRc(NamedPipeClient pipe, DV_RC_EntryPoint rc_EntryPoint, int allowedAttempts, int counter){
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
boolean connected = false;
ScheduledFuture<?> countdown = scheduler.schedule(new Runnable() {
@Override
public void run() {
connected = attemptRetrievalOfSwitches(pipe, rc_EntryPoint, allowedAttempts, counter);
}}, 1, TimeUnit.MINUTES);
return connected;
}
你能編輯代碼嗎? – Harriet