源码(@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

最新文章

  1. JSHelper时间格式化
  2. xml配置文件的读写
  3. 查看 并发请求数及其TCP连接状态【转】
  4. java高薪之路__007_反射
  5. windows下重启mysql
  6. LeetCode: Lowest Common Ancestor of a Binary Search Tree 解题报告
  7. 有关对字符串的处理,需要用到List时的简化写法
  8. Matrix 二维树状数组的第二类应用
  9. Drools
  10. C++对象模型2--指针cout结果
  11. zBase --轻量级DOM操作库
  12. QUICK-AP + BETTERCAP 搭建热点, 欺骗局域网内用户下载任意可执行文件
  13. RTMP协议中文翻译(首发)
  14. Selenium_WebDriver_定位元素
  15. 【转载】java abstract class和interface的区别
  16. django rest_framework 序列化组件详解
  17. Nmap 使用技巧及其攻略
  18. JAVA框架 SpringMVC RequestMapping讲解
  19. windows系统中Dotnet core runtime 安装后,无法启动次程序,因为计算机中丢失api-ms-win-crt-runtime-l1-1-0.dll的解决方法
  20. python 进程队列

热门文章

  1. JSP和Struts2、Hibernate、Spring3基础内容和原理
  2. 前端-JavaScript1-7——JavaScript之数学运算符
  3. redis的pub/sub命令
  4. About Gnu Linker1
  5. jenkins自动构建站点
  6. 移植QT库的问题:QT_INSTALL/include/QtCore/qatomic_arm.h:131: Error: no such instruction: `swpb %al,
  7. jmeter联合selenium webdriver进行自动化测试-简单1
  8. Android 开发 获取Android设备的屏幕高宽
  9. 在c#中利用keep-alive处理socket网络异常断开的方法
  10. Linux查看密码