Can I avoid repeating myself in this situation (Java)

Posted by UltimateGuy on Stack Overflow See other posts from Stack Overflow or by UltimateGuy
Published on 2010-06-08T23:03:13Z Indexed on 2010/06/08 23:12 UTC
Read the original article Hit count: 235

Filed under:
|
|
 if (openFile == null) {

      new AppFileDialog().chooseFile("Save", appFrame);

 }

 if (openFile == null) {

      return;

 }

Here I need to check to see if the user has already chosen a file. If not, they are given a prompt to. If the file is still null, the function returns without saving. The problem is the two identical if statements, can I avoid it? I take DRY very seriously, but at the same time KISS. Ideally the two go hand in hand, but in a situation like this, it seems they are mutually exclusive.

© Stack Overflow or respective owner

Related posts about java

Related posts about dry