?一个try catch 中的return 问题

来源:互联网 发布:网络彩票代理怎么做的 编辑:程序博客网 时间:2024/04/30 02:38
//源码:
public class Test {    public static void main(String... args) {        System.out.println(getValue1());        System.out.println(getValue2());    }     public static int getValue1() {        int i1 = 0;        int i2 = 1;        try {            return i1;        } finally {            return i2;        }    }     public static int getValue2() {        int i = 1;        try {            return i;        } finally {            i++;        }    }}

使用JAD编译后的代码:
public class Test{    public Test()    {    }    public static transient void main(String args[])    {        System.out.println(getValue1());        System.out.println(getValue2());    }    public static int getValue1()    {        boolean flag;        int i;        flag = false;        i = 1;        boolean flag1 = flag;        return i;        Exception exception;        exception;        return i;    }    public static int getValue2()    {        int i = 1;        int j = i;//这里使用了临时变量        i++;        return j;        Exception exception;        exception;        i++;        throw exception;    }}
可以看出JVM对于处理这样的情况使用临时变量处理的。
原创粉丝点击