Skip to main content

proposal: defining inner methods

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
enricjaen
Offline
Joined: 2007-08-22

Hello, it's a good practice to decompose a large method into smaller pieces. However this creates many private methods at the class level. I wonder if you would find intesting to have inner methods, similar to anoymous classes.

For example:

(sorry for the markup but the forum form doesn't work)

</p>
<p>class AAA {<br />
   public largeMethod() {<br />
        piece1();<br />
        piece2();<br />
        piece3();<br />
        piece4();<br />
  }</p>
<p>  private void piece1 { ... }<br />
  private void piece2{ ... }<br />
  private void piece3 { ... }<br />
  private void piece4 { ... }</p>
<p>}</p>
<p>

would become:

</p>
<p>class AAA {<br />
   public largeMethod() {<br />
        piece1();<br />
        piece2();<br />
        piece3();<br />
        piece4();</p>
<p>       void piece1 { ... }<br />
       void piece2{ ... }<br />
       void piece3 { ... }<br />
       void piece4 { ... }<br />
  }</p>
<p>}</p>
<p>

What do you think?

Regards,
/Enric