关键字:jvm try catch finally return、指令

  1. finally相当于在所有方法返回之前执行一次
  2. finally中含有return其中finally中return会覆盖try和catch中的return
  3. finally中不含return时,会先将try或catch中的返回值储存在局部变量表中,最后执行返回是加载到操作数栈返回
public class FinallyReturnBean {

    public int sayGoodBye(int divide){
int c = 0;
try {
c = 1000/divide;
return c;
}catch (Exception e){
c = 500;
return c;
}finally {
c =300;
// return c;//#1 注释return c; #2 不注释 return c;
}
} public static void main(String[] args) {
System.out.println(new FinallyReturnBean().sayGoodBye( 0));
System.out.println(new FinallyReturnBean().sayGoodBye( 1));
} // #1 注释return c; 500;1000
// public class com.lsl.common.jvm.bean.FinallyReturnBean {
// public com.lsl.common.jvm.bean.FinallyReturnBean();
// Code:
// 0: aload_0
// 1: invokespecial #1 // Method java/lang/Object."<init>":()V
// 4: return // public int sayGoodBye(int);
// Code:
// 0: iconst_0
// 1: istore_2
// 2: sipush 1000
// 5: iload_1
// 6: idiv
// 7: istore_2
// 8: iload_2
// 9: istore_3 --slot3
// 10: sipush 300
// 13: istore_2
// 14: iload_3 --slot3
// 15: ireturn --1000
// 16: astore_3
// 17: sipush 500
// 20: istore_2
// 21: iload_2
// 22: istore 4
// 24: sipush 300
// 27: istore_2
// 28: iload 4
// 30: ireturn --
// 31: astore 5
// 33: sipush 300
// 36: istore_2
// 37: aload 5
// 39: athrow
// Exception table:
// from to target type
// 2 10 16 Class java/lang/Exception
// 2 10 31 any
// 16 24 31 any
// 31 33 31 any
// } // #2 不注释 return c; 300;300 try return失效
// public class com.lsl.common.jvm.bean.FinallyReturnBean {
// public com.lsl.common.jvm.bean.FinallyReturnBean();
// Code:
// 0: aload_0
// 1: invokespecial #1 // Method java/lang/Object."<init>":()V
// 4: return
//
// public int sayGoodBye(int);
// Code:
// 0: iconst_0
// 1: istore_2
// 2: sipush 1000
// 5: iload_1
// 6: idiv
// 7: istore_2
// 8: iload_2
// 9: istore_3
// 10: sipush 300
// 13: istore_2
// 14: iload_2
// 15: ireturn --
// 16: astore_3
// 17: sipush 500
// 20: istore_2
// 21: iload_2
// 22: istore 4
// 24: sipush 300
// 27: istore_2
// 28: iload_2
// 29: ireturn --
// 30: astore 5
// 32: sipush 300
// 35: istore_2
// 36: iload_2
// 37: ireturn --
// Exception table:
// from to target type
// 2 10 16 Class java/lang/Exception
// 2 10 30 any
// 16 24 30 any
// 30 32 30 any
// } }

最新文章

  1. 设计模式C#实现(十六)——中介者模式
  2. socketserver服务器
  3. js和jquery页面初始化加载函数的方法及先后顺序
  4. qunit学习(一)
  5. Perl中的正则表达式
  6. Cheatsheet: 2013 07.01 ~ 07.08
  7. P1231: [Usaco2008 Nov]mixup2 混乱的奶牛
  8. codeforces 579D D. &quot;Or&quot; Game(前后缀+贪心)
  9. require.js入门指南(一)
  10. BZOJ2213: [Poi2011]Difference
  11. Struts 和Spring的核心控制器
  12. Effective Modern C++ Item 37:确保std::thread在销毁时是unjoinable的
  13. Android Paint类介绍以及浮雕和阴影效果的设置
  14. [CTSC2017]网络
  15. 关于Collections.sort()排序方法的源码探索
  16. pip问题
  17. opencv学习笔记(一)
  18. Win10系列:VC++调用自定义组件2
  19. MethodInfo类的一般使用
  20. keras中TimeDistributed

热门文章

  1. CSMA/CD协议(载波侦听多路访问/碰撞检测) 最小帧长理解
  2. xml schema杂谈
  3. SpringMvc异常处理和SpringMvc拦截器
  4. 【转载-学习】[一个前端必会的 Nginx免费教程 - 技术胖]
  5. Flink的流处理API(二)
  6. 【Python学习笔记】字符串拼接方法(5种)总结
  7. MacOS下如何优雅的使用冰蝎
  8. SqlServer 版本号
  9. JS学习第一天
  10. C#LeetCode刷题-递归