Stop executing further code in Java

后端 未结 6 2044
失恋的感觉
失恋的感觉 2021-01-01 16:25

I have looked in the Javadoc but couldn\'t find information related to this.

I want the application to stop executing a method if code in that method tells it to do

6条回答
  •  孤独总比滥情好
    2021-01-01 17:16

    Just do:

    public void onClick() {
        if(condition == true) {
            return;
        }
        string.setText("This string should not change if condition = true");
    }
    

    It's redundant to write if(condition == true), just write if(condition) (This way, for example, you'll not write = by mistake).

提交回复
热议问题