我只是感到困惑,是要执行return语句之后的方法还是将其视为变量。
例:

public boolean onSystemChecked(boolean dubug){
  if(this.isActivated()) {
    return this.ActivateAction();
  } else {
    if(debug) {
      System.out.println("[Debug] System Off!");
    }
  }
  return false;
}

会执行this.ActivateAction()吗?非常感谢你! :)

最佳答案

会执行this.ActivateAction()吗?


是。否则,该方法将不知道返回什么!

return语句首先对表达式求值,然后返回该值。当然,在void方法中只有一个return语句的情况下

return;


没有什么可评估的。

有关更多详细信息,请参见14.17 of the Java Language Specification部分。

关于java - Java在return语句之后执行方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15473682/

10-14 20:24
查看更多