java中finally里面的代码一定会执行吗?(try里面做了return呢?)

直接看例子:

public class TryFinallyTest {
    public static void main(String[] args) {
        try{
            System.out.println("hello finally");
            return;
        }finally {
            System.out.println("execute finally even try's block has return");
        }
    }
}

再看执行结果:

 

hello finally
execute finally even try's block has return

Process finished with exit code 0

posted on 2021-05-09 12:52  坚守梦想  阅读(126)  评论(0编辑  收藏  举报