有以下程序 :
public class FinallyTest
{
public static void main(String args[])
{
System.out.println("in main return: " + new FinallyTest().getString());
}
public String getString()
{
String returnString = null;
try
{
returnString = "this string will be return.";
return returnString;
}finally
{
System.out.println("execute finally...");
System.out.println("before clean returnString's value: " + returnString);
returnString = null;
System.out.println("after clean returnString's value: " + returnString);
System.out.println("execute finally end.");
}
}
}
输入出结果是:
execute finally...
before clean returnString's value: this string will be return.
after clean returnString's value: null
execute finally end.
in main return: this string will be return.