if (isSpecialDeal()) { total = price * 0.95; send(); } else { total = price * 0.98; send(); }
if (isSpecialDeal()) total = price * 0.95; else total = price * 0.98; send();
For more information see page 243 of Refactoring
Paul Haahr rightly took me to task for being far too glib when I talked about consolidating with exceptions. You can only pull repeated code into a final block if all non-fatal exceptions are caught. This is because the finally block is executed after any exception, including those that don't have a catch clause. (Of course you may prefer that to happen, but that's not a semantics preserving change.)