探究编译后,try-with-resources括号中的object是否关闭,以及两种写法编译后的对比
源码(@TargetApi(Build.VERSION_CODES.KITKAT))
- public List<T> test1() {
- String sql = "selxe xxxxxxxxxxx";
- try (Cursor cursor = dbManager.getReadableDatabase().rawQuery(sql, null)) {
- List<T> lst = new ArrayList<>();
- while (cursor.moveToNext()) {
- lst.add(findEntity(cursor));
- }
- return lst;
- }
- }
- public List<T> test2() {
- String sql = "selxe xxxxxxxxxxx";
- Cursor cursor = dbManager.getReadableDatabase().rawQuery(sql, null);
- try {
- List<T> lst = new ArrayList<>();
- while (cursor.moveToNext()) {
- lst.add(findEntity(cursor));
- }
- return lst;
- } finally {
- cursor.close();
- }
- }
反编译后
- public List<T> test1()
- {
- Cursor localCursor = this.dbManager.getReadableDatabase().rawQuery("selxe xxxxxxxxxxx", null);
- try
- {
- localArrayList = new ArrayList();
- while (localCursor.moveToNext())
- localArrayList.add(findEntity(localCursor));
- }
- catch (Throwable localThrowable3)
- {
- ArrayList localArrayList;
- Object localObject1;
- try
- {
- throw localThrowable3;
- }
- finally
- {
- localThrowable1 = localThrowable3;
- }
- if ((localCursor == null) || (localThrowable1 != null));
- while (true)
- {
- try
- {
- localCursor.close();
- throw localObject1;
- if ((localCursor == null) || (0 != 0))
- try
- {
- localCursor.close();
- return localArrayList;
- }
- catch (Throwable localThrowable4)
- {
- null.addSuppressed(localThrowable4);
- return localArrayList;
- }
- localCursor.close();
- return localArrayList;
- }
- catch (Throwable localThrowable2)
- {
- localThrowable1.addSuppressed(localThrowable2);
- continue;
- }
- localCursor.close();
- }
- }
- finally
- {
- while (true)
- Throwable localThrowable1 = null;
- }
- }
- public List<T> test2()
- {
- Cursor localCursor = this.dbManager.getReadableDatabase().rawQuery("selxe xxxxxxxxxxx", null);
- ArrayList localArrayList;
- try
- {
- localArrayList = new ArrayList();
- while (localCursor.moveToNext())
- localArrayList.add(findEntity(localCursor));
- }
- finally
- {
- localCursor.close();
- }
- localCursor.close();
- return localArrayList;
- }
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是否关闭,以及两种写法编译后的对比的更多相关文章
- ASP.NET MVC中获取URL地址参数的两种写法
一.url地址传参的第一种写法 1.通过mvc中默认的url地址书写格式:控制器/方法名/参数 2.实例:http://localhost:39270/RequestDemo/Index/88,默认参 ...
- C#字段中加入list<类字段> 的两种写法
类1 public class NumCon { public string zsNum { get; set; } } 类2 public class RepeatMess //重复数据响应 { p ...
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- 在Java Web程序中使用监听器可以通过以下两种方法
之前学习了很多涉及servlet的内容,本小结我们说一下监听器,说起监听器,编过桌面程序和手机App的都不陌生,常见的套路都是拖一个控件,然后给它绑定一个监听器,即可以对该对象的事件进行监听以便发生响 ...
- Eclipse中SVN的安装步骤(两种)和使用方法
Eclipse中SVN的安装步骤(两种)和使用方法 一.给Eclipse安装SVN,最常见的有两种方式:手动方式和使用安装向导方式.具体步骤如下: 方式一:手动安装 1.下载最新的Eclipse,我的 ...
- [转]MFC子线程中更新控件内容的两种办法
一.概述 每个系统中都有线程(至少都有一个主线程),而线程最重要的作用就是并行处理,提高软件的并发率.针对界面来说,还能提高界面的响应能力.一般的,为了应用的稳定性,在数据处理等耗时操作会单独在一个线 ...
- js如何实现动态的在表格中添加和删除行?(两种方法)
js如何实现动态的在表格中添加和删除行?(两种方法) 一.总结 1.table元素有属性和一些方法(js使用) 方法一:添加可通过在table的innerHTML属性中添加tr和td来实现 tab.i ...
- Java 获取*.properties配置文件中的内容 ,常见的两种方法
import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...
- python中字典的循环遍历的两种方式
开发中经常会用到对于字典.列表等数据的循环遍历,但是python中对于字典的遍历对于很多初学者来讲非常陌生,今天就来讲一下python中字典的循环遍历的两种方式. 注意: python2和python ...
随机推荐
- kong插件应用
插件概述 插件之于kong,就像Spring中的aop功能.在请求到达kong之后,转发给后端应用之前,你可以应用kong自带的插件对请求进行处理,合法认证,限流控制,黑白名单校验,日志采集等等.同时 ...
- css -理解盒模型
标准模式: 总宽度/高度=width/height+padding+border+margin 怪异模式(quirks 模式): 总宽度/高度=width/height + margin = 内容区宽 ...
- note 9 列表、时间复杂度、排序
列表 List +内建(built-in)数据结构(data structure),用来存储一系列元素(items) 如:lst = [5.4,'hello',2] 前向索引.后向索引.切片.拼接.成 ...
- idea properties文件中文无法正常显示
引用:https://blog.csdn.net/u010999809/article/details/81204457 问题:在idea打开配置文件,已经设置了全局编码格式为UTF-8,和项目编码格 ...
- remote: Repository not found. fatal: repository 'https://github.com/***/***.git/' not found
通过命令添加新repository到git hub在执行最后一步命令(如下所示)的时候报错 git push -u origin master error:remote: Repository not ...
- 图表相同数据会自动合并问题(finereport)
finereport中,对于图表的操作,当遇到需要显示多个重复分类下的多个值时,由于自动合并相同数据,无法达到效果反复查询手册无果后,困扰好久,终想到了一个解决的办法:1.给查询的数据添加个列序号,每 ...
- mybaties插件生成代码
指定插件运行什么xml,关于如何用idea创建一个maven项目,可以看我以前写的博客 <?xml version="1.0" encoding="UTF-8&qu ...
- @Override is not allowed when implementing interface method
使用idea导入maven项目时 会出现如下报错 @Override从jdk1.5开始出现的,是用来标注方法重写:通常方法重写发生在继承父类,重写父类方法,或者实现接口,实现接口方法: @Overri ...
- JS时间戳转时间
function timestampToTime(timestamp) { S = timestamp, T = new Date(1E3 * S), Format = function(Q){ret ...
- css实现布局
1.两栏布局 两栏布局一般就是一栏定宽一栏自适应(也就是流动).分的细的话还有左栏定宽右栏自适应.右栏定宽左栏自适应. 举个栗子:一栏定宽200px,一栏自适应. <head> <m ...