finally節は必ず実行される
try { System.out.println("try"); return; // ここにリターンがあってもfinally節は実行される // catch省略可 } finally { System.out.println("finally"); } // System.out.println("end"); // これをここに入れるとコンパイルエラーに(unreachable code)
output:
try finally
try { System.out.println("try"); return; // ここにリターンがあってもfinally節は実行される // catch省略可 } finally { System.out.println("finally"); } // System.out.println("end"); // これをここに入れるとコンパイルエラーに(unreachable code)
output:
try finally