探究编译后,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 ...
随机推荐
- js通过replace()方法配合正则去除空格
<script> //去掉全部空格 var str = " 546546 4564 46 46 88 88 "; var str = str.replace(/\s+/ ...
- Next.js 分页组件
import React from 'react'; import './NxPagination.less'; export default class NxPagination extends R ...
- React 环境增加Redux ,React-Redux
引入 Redux 的目的, 状态管理! React-Redux 就是完成一些粘合剂的作用. 简而化之的理解就是将数据放在store 中维护, 操作逻辑放在reducer中去写. 更功利的表达就是: ...
- spring资源加载结构解析
1.spring中资源加载使用resources的原因? 在java将不同资源抽象成url,然后通过注册不同的hander来处理不同读取逻辑,一般hander使用协议的前缀来命名,如http,jar, ...
- 刘志梅201771010115.《面向对象程序设计(java)》第十七周学习总结
实验十七 线程同步控制 实验时间 2018-12-10 1.实验理论知识 多线程 多线程是进程执行过程中产生的多条执行线索.进程 线程是比进程执行更小的单位.线程不能独立存在,必须存在于 ...
- On-die termination for DDR
本文转载自: https://blog.csdn.net/weixin_38233274/article/details/81016870 ODT是什么鬼?为什么要用ODT?在很多关于DDR3的博文和 ...
- 安卓ndk 忽略 error: undefined reference to '找不到符号
最近在搞天使之翼的mrp模拟器... 移到AndroidStudio了,现在想把原来的Android .mk那种方式的改成cmake的方式编译,但是编译时有一些符号找不到. undefined ref ...
- springCloud 服务注册启动报错<com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect>
报错:com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: ...
- IDEA tomcat8 控制台日志乱码
瞎扯一句:由于tomcat7之前编码默认都是GBK,tomcat8之后都是UTF-8 1.在idea64.exe.vmoptions(我装的是64位的)最后加入 -Dfile.encoding=UTF ...
- C# Global定时执行Global文件aTimer处理
public class Global : System.Web.HttpApplication { private static event Action eventActions; /// < ...