, return, , tryOne(): builder . , , , finally . , - :
protected StringBuilder tryOne() {
StringBuilder builder = new StringBuilder();
try {
builder.append("Cool");
builder.append("Return");
StringBuilder temp = builder;
return temp;
} finally {
builder = null;
}
}
, , ( , ), :
protected StringBuilder tryOne() {
StringBuilder builder = new StringBuilder();
builder.append("Cool");
builder.append("Return");
StringBuilder temp = builder;
builder = null;
return temp;
}
builder = null , . builder.append("something") , temp, builder () .
, trySeven(), :
protected int trySeven() {
int count = 0;
count = 99;
int temp = count;
count++;
return temp;
}
, int, , .
All that has been said remains a fact: including return statements in the try-finally block is pretty confusing, so if you have any choice in this matter, you'd better rewrite things so that all your return statements are outside of try blocks -finally.
source
share