使用 Finally 的疑惑,请大家一起讨论!

有以下代码:

public class FinallyTest1   
{  
    public static void main(String args[])  
    {  
        System.out.println("return: " + new FinallyTest1().getMessage().message);  
    }  
      
    public Message getMessage()  
    {  
        Message returnMessage = new Message();  
        try  
        {  
            returnMessage.message = "message";  
            return returnMessage;         
        }finally  
        {             
            System.out.println("execute finally...");  
            System.out.println("before clean returnString's value: " + returnMessage.message);  
            returnMessage.message = null;  
            System.out.println("after  clean returnString's value: " + returnMessage.message);  
            System.out.println("execute finally end.");  
        }         
    }  
}  
  
class Message  
{  
    public String message = "message";  
}  

 输出结果是:

execute finally...
before clean returnString's value: message
after  clean returnString's value: null
execute finally end.
return: null

你可能感兴趣的:(finally)