关于finally

下面代码输出什么?

package com.example.javademo;

public class RetrunFinally {
    public static void main(String[] args) {
        try {
            System.out.println("return");
            return;
        } finally {
            System.out.println("finally");
        }
    }
}

答案:

return
finally

记住:

finally代码块总是执行!

你可能感兴趣的:(关于finally)