try -finally的執行順序

import org.junit.Test;

import com.wangge.test1.Person;

public class FinalTest {
  
  
  /** 
    * testReturn:.  <br/> 
    * @author yangqc  
    * @since JDK 1.8 
    */  
  @Test
  public void testReturn(){
  System.out.println("返回結果"+getd());//輸出:返回結果5
  }
  
  /** 
    * getd: rturn a 會存儲起來,執行完finally的內容以後執行該控制語句,. <br/> 
  
    * @author yangqc 
    * @return 
    * @since JDK 1.8 
    */  
  public int getd(){
    int a=3;
    try{
      a=5;
      return a;
    }finally{
      a=4;
      System.out.println(4);
    }
  } 
  /** 
    * test2:(這裏用一句話描述這個方法的做用). <br/> 
    * 輸出:0 1 2 4,
    * finally裏的continue執行了,該線程結束,try裏的break就不執行了.
    * @author yangqc  
    * @since JDK 1.8 
    */  
  @Test
  public void test2(){
    for(int i=0;i<5;i++){
      try {
        if(i==3){
          break;
        }
        System.out.println(i);
      } finally {
       if(i==3){
         continue;
       }
      }
    }
  }
 
}
相關文章
相關標籤/搜索