http://www.importnew.com/21445.html

 

1. 问,以下,会返回什么。

public int func() {
        int ret = 0;
        try{
            throw new Exception();
        }
        catch(Exception e){
            ret = 1;
            return ret;
        }
        finally{
            ret = 2;
            System.out.printf("Set ret to %d\n", ret);
        }
    }

答案:

Set ret to 2
1

因为,虽然finally里面的代码会执行,但是catch里面的return值已经在另外的地方保存起来了。

 

相关文章:

  • 2021-12-22
  • 2021-07-17
  • 2021-12-03
  • 2022-01-17
  • 2021-10-03
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2021-07-20
  • 2022-01-27
  • 2021-02-18
  • 2021-09-13
  • 2021-04-30
相关资源
相似解决方案