源码(@TargetApi(Build.VERSION_CODES.KITKAT))

  1. public List<T> test1() {
  2. String sql = "selxe xxxxxxxxxxx";
  3. try (Cursor cursor = dbManager.getReadableDatabase().rawQuery(sql, null)) {
  4. List<T> lst = new ArrayList<>();
  5. while (cursor.moveToNext()) {
  6. lst.add(findEntity(cursor));
  7. }
  8. return lst;
  9. }
  10. }
  11.  
  12. public List<T> test2() {
  13. String sql = "selxe xxxxxxxxxxx";
  14. Cursor cursor = dbManager.getReadableDatabase().rawQuery(sql, null);
  15. try {
  16. List<T> lst = new ArrayList<>();
  17. while (cursor.moveToNext()) {
  18. lst.add(findEntity(cursor));
  19. }
  20. return lst;
  21. } finally {
  22. cursor.close();
  23. }
  24. }

反编译后

  1. public List<T> test1()
  2. {
  3. Cursor localCursor = this.dbManager.getReadableDatabase().rawQuery("selxe xxxxxxxxxxx", null);
  4. try
  5. {
  6. localArrayList = new ArrayList();
  7. while (localCursor.moveToNext())
  8. localArrayList.add(findEntity(localCursor));
  9. }
  10. catch (Throwable localThrowable3)
  11. {
  12. ArrayList localArrayList;
  13. Object localObject1;
  14. try
  15. {
  16. throw localThrowable3;
  17. }
  18. finally
  19. {
  20. localThrowable1 = localThrowable3;
  21. }
  22. if ((localCursor == null) || (localThrowable1 != null));
  23. while (true)
  24. {
  25. try
  26. {
  27. localCursor.close();
  28. throw localObject1;
  29. if ((localCursor == null) || (0 != 0))
  30. try
  31. {
  32. localCursor.close();
  33. return localArrayList;
  34. }
  35. catch (Throwable localThrowable4)
  36. {
  37. null.addSuppressed(localThrowable4);
  38. return localArrayList;
  39. }
  40. localCursor.close();
  41. return localArrayList;
  42. }
  43. catch (Throwable localThrowable2)
  44. {
  45. localThrowable1.addSuppressed(localThrowable2);
  46. continue;
  47. }
  48. localCursor.close();
  49. }
  50. }
  51. finally
  52. {
  53. while (true)
  54. Throwable localThrowable1 = null;
  55. }
  56. }
  57.  
  58. public List<T> test2()
  59. {
  60. Cursor localCursor = this.dbManager.getReadableDatabase().rawQuery("selxe xxxxxxxxxxx", null);
  61. ArrayList localArrayList;
  62. try
  63. {
  64. localArrayList = new ArrayList();
  65. while (localCursor.moveToNext())
  66. localArrayList.add(findEntity(localCursor));
  67. }
  68. finally
  69. {
  70. localCursor.close();
  71. }
  72. localCursor.close();
  73. return localArrayList;
  74. }

The try-with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.

参考:https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

探究编译后,try-with-resources括号中的object是否关闭,以及两种写法编译后的对比的更多相关文章

  1. ASP.NET MVC中获取URL地址参数的两种写法

    一.url地址传参的第一种写法 1.通过mvc中默认的url地址书写格式:控制器/方法名/参数 2.实例:http://localhost:39270/RequestDemo/Index/88,默认参 ...

  2. C#字段中加入list<类字段> 的两种写法

    类1 public class NumCon { public string zsNum { get; set; } } 类2 public class RepeatMess //重复数据响应 { p ...

  3. ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法

    ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块  --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...

  4. 在Java Web程序中使用监听器可以通过以下两种方法

    之前学习了很多涉及servlet的内容,本小结我们说一下监听器,说起监听器,编过桌面程序和手机App的都不陌生,常见的套路都是拖一个控件,然后给它绑定一个监听器,即可以对该对象的事件进行监听以便发生响 ...

  5. Eclipse中SVN的安装步骤(两种)和使用方法

    Eclipse中SVN的安装步骤(两种)和使用方法 一.给Eclipse安装SVN,最常见的有两种方式:手动方式和使用安装向导方式.具体步骤如下: 方式一:手动安装 1.下载最新的Eclipse,我的 ...

  6. [转]MFC子线程中更新控件内容的两种办法

    一.概述 每个系统中都有线程(至少都有一个主线程),而线程最重要的作用就是并行处理,提高软件的并发率.针对界面来说,还能提高界面的响应能力.一般的,为了应用的稳定性,在数据处理等耗时操作会单独在一个线 ...

  7. js如何实现动态的在表格中添加和删除行?(两种方法)

    js如何实现动态的在表格中添加和删除行?(两种方法) 一.总结 1.table元素有属性和一些方法(js使用) 方法一:添加可通过在table的innerHTML属性中添加tr和td来实现 tab.i ...

  8. Java 获取*.properties配置文件中的内容 ,常见的两种方法

    import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...

  9. python中字典的循环遍历的两种方式

    开发中经常会用到对于字典.列表等数据的循环遍历,但是python中对于字典的遍历对于很多初学者来讲非常陌生,今天就来讲一下python中字典的循环遍历的两种方式. 注意: python2和python ...

随机推荐

  1. kong插件应用

    插件概述 插件之于kong,就像Spring中的aop功能.在请求到达kong之后,转发给后端应用之前,你可以应用kong自带的插件对请求进行处理,合法认证,限流控制,黑白名单校验,日志采集等等.同时 ...

  2. css -理解盒模型

    标准模式: 总宽度/高度=width/height+padding+border+margin 怪异模式(quirks 模式): 总宽度/高度=width/height + margin = 内容区宽 ...

  3. note 9 列表、时间复杂度、排序

    列表 List +内建(built-in)数据结构(data structure),用来存储一系列元素(items) 如:lst = [5.4,'hello',2] 前向索引.后向索引.切片.拼接.成 ...

  4. idea properties文件中文无法正常显示

    引用:https://blog.csdn.net/u010999809/article/details/81204457 问题:在idea打开配置文件,已经设置了全局编码格式为UTF-8,和项目编码格 ...

  5. remote: Repository not found. fatal: repository 'https://github.com/***/***.git/' not found

    通过命令添加新repository到git hub在执行最后一步命令(如下所示)的时候报错 git push -u origin master error:remote: Repository not ...

  6. 图表相同数据会自动合并问题(finereport)

    finereport中,对于图表的操作,当遇到需要显示多个重复分类下的多个值时,由于自动合并相同数据,无法达到效果反复查询手册无果后,困扰好久,终想到了一个解决的办法:1.给查询的数据添加个列序号,每 ...

  7. mybaties插件生成代码

    指定插件运行什么xml,关于如何用idea创建一个maven项目,可以看我以前写的博客 <?xml version="1.0" encoding="UTF-8&qu ...

  8. @Override is not allowed when implementing interface method

    使用idea导入maven项目时 会出现如下报错 @Override从jdk1.5开始出现的,是用来标注方法重写:通常方法重写发生在继承父类,重写父类方法,或者实现接口,实现接口方法: @Overri ...

  9. JS时间戳转时间

    function timestampToTime(timestamp) { S = timestamp, T = new Date(1E3 * S), Format = function(Q){ret ...

  10. css实现布局

    1.两栏布局 两栏布局一般就是一栏定宽一栏自适应(也就是流动).分的细的话还有左栏定宽右栏自适应.右栏定宽左栏自适应. 举个栗子:一栏定宽200px,一栏自适应. <head> <m ...