探究编译后,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 ...
随机推荐
- Spring编程式事务管理和声明式事务管理
本来想写一篇随笔记一下呢,结果发现一篇文章写的很好了,已经没有再重复写的必要了. https://www.ibm.com/developerworks/cn/education/opensource/ ...
- multipart/form-data和application/x-www-form-urlencoded区别
FORM元素的enctype属性指定了表单数据向服务器提交时所采用的编码类型.例如: application/x-www-form-urlencoded: 窗体数据被编码为名称/值对.这是标准的编码格 ...
- 进程间传递文件描述符——sendmsg和recvmsg函数
先引入一个例子,该程序的目的是子进程向父进程传递文件描述符,并通过该文件描述符读取buf. #include <func.h> int main(){ int fds[2]; pipe(f ...
- listview-android:打造万能通用适配器(转)
转载:https://blog.csdn.net/q649381130/article/details/51781921: 1.前言 listview作为安卓项目中一个的明星控件,它的适配器的写法是广 ...
- .net core Ocelot实现API网关并部署在docker中
基于Ocelot(http://ocelot.readthedocs.io)搭建的API网关demo 软件以及系统版本: Asp.Net Core 2.2 Ocelot 13.5.0 CentOS ...
- Express路由
1. 路由器的配置分为两个,一个是需要做页面的渲染,一个是需要直接进行对数据进行输出,对于路由器的配置需要对路由器在公共的app.js进行注册与注入才能生效,否则是不能生效的.配置时根据不同的应用场景 ...
- 【转录组入门】6:reads计数
作业要求: 实现这个功能的软件也很多,还是烦请大家先自己搜索几个教程,入门请统一用htseq-count,对每个样本都会输出一个表达量文件. 需要用脚本合并所有的样本为表达矩阵.参考:生信编程直播第四 ...
- suList() 和 asList()
String[] arr = { "a", "b", "c" }; List<String> aslist = Arrays.a ...
- 记录一次 “ORA-12516:TNS:监听程序找不到符合协议堆栈要求的可用处理程序” 的处理过程
一.今天同事反馈业务化运行的数据中心库发生了oracle无法连接的情况,导致所有业务系统无法正常运作的问题.报:“ORA-12516:TNS:监听程序找不到符合协议堆栈要求的可用处理程序” 二.收到这 ...
- mvc开发中DTO,DO,FROM的区别
DO:数据库实体类映射到model里的实体类,每个字段都和数据库相对应,一般来说开发的时候不要去添加或者修改里面的实体 DTO:与前台交互的时候(一般来说是查询操作)有一些数据字段是那一张表里面没有囊 ...