java if终止_java – “return”是否停止执行方法?

我已经按照以下方式编写了一个方法:

if (something) {

return 1;

}

the rest of the code

在我看来,该方法返回1,然后执行其余的代码.真的可以吗不返回停止代码的执行.它不是,我如何强制一种方法停止?

这是代码(根据要求):

for (int i=availableTime; i>0; i=i-1) {

final int sec = i;

SwingUtilities.invokeLater(new Runnable() {

public void run() {

String lbl = "";

lbl += "";

timeLeftLabel.setText(lbl);

}

});

try {Thread.sleep(1000);} catch (InterruptedException e) {}

parameterFromClientsListener = clientsListener.getValue(userName,parameterToGet);

if (!parameterFromClientsListener.equals("null")) {

output = parameterFromClientsListener;

game.log.fine(userName + " set (by button) " + parameterToGet + " to be equal to " + output + " . [IMPORTANT]");

return output;

}

}

game.log.fine("The partner selection phase is expired.");

// This code is executed if the Submit button was not pressed and the time run out.

if (parameterToGet.equals("partner")) {

tellMyChoice(parameterToGet,this.partnerFromForm,"timer of" + field);

output = this.partnerFromForm;

}

game.log.fine(parameterToGet + " was submitted by timer (not by OK button).");

} else {

output = parameterFromClientsListener;

}

game.log.fine(userName + " set (by timer)" + parameterToGet + " to be equal to " + output + " . [IMPORTANT]");

return output;

}

我运行这段代码两次.在每种情况下,我都会生成一个日志文件.在两个日志文件中,我看到“set(by button)”语句(在返回之前是直接的).但问题是在第二个日志文件中我看到“timer of”语句.如果达到“设定(按钮)”,则不能达到.怎么会这样?我需要提到的是,“set(by button)”和“timer”不会发生在我的代码中的任何地方(它们只发生一次).

从代码可以看出,我没有finally语句.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值