Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only way to do this without change method two() is to throw an Exception.</p> <p>If you can change the code you can return a boolean which tells the caller to return.</p> <p>However the simplest solution is to inline the methods into one larger method. If this is too large you should retsructure it another way and not place complex controls between methods like this.</p> <hr> <p>Say you have </p> <pre><code>public void one() { System.out.println("Start of one."); two(); // do something System.out.println("End of one."); } public void two() { System.out.println("Start of two."); three(); // do something System.out.println("End of two."); } public void three() { System.out.println("Start of three."); // do something System.out.println("End of three."); } </code></pre> <hr> <p>You can add an unchecked exception if you cannot change two();</p> <pre><code>public void one() { System.out.println("Start of one."); try { two(); } catch (CancellationException expected) { } // do something System.out.println("End of one."); } public void two() { System.out.println("Start of two."); three(); // do something System.out.println("End of two."); } public void three() { System.out.println("Start of three."); // do something System.out.println("End of three."); throw new CancellationException(); // use your own exception if possible. } </code></pre> <hr> <p>You can return a boolean to say return, if you can change two()</p> <pre><code>public void one() { System.out.println("Start of one."); two(); // do something System.out.println("End of one."); } public void two() { System.out.println("Start of two."); if (three()) return; // do something System.out.println("End of two."); } public boolean three() { System.out.println("Start of three."); // do something System.out.println("End of three."); return true; } </code></pre> <hr> <p>Or you can inline the structures</p> <pre><code>public void one() { System.out.println("Start of one."); two(); // do something System.out.println("End of one."); } public void two() { System.out.println("Start of two."); System.out.println("Start of three."); // do something for three System.out.println("End of three."); boolean condition = true; if (!condition) { // do something for two System.out.println("End of two."); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload