This is clearly highly subjective. I personally find the logic of the very short method using finally
hard to follow.
To my eye, the following is clearer:
public String getSbValue() {
StringBuffer prev_sb = sb;
sb = new StringBuffer();
return prev_sb.toString();
}
(Your second example, while being similar to my code above is different, and has different semantics to your first example.)
P.S. You should almost certainly be using StringBuilder
in place of StringBuffer
.