我有下面的定时器代码,并且根据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