Interface AutoCloseable
https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html
https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html
public interface AutoCloseable
close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.Method Detail
close
void close()
throws ExceptionCloses this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by thetry-with-resources statement.While this interface method is declared to throw
Exception, implementers are strongly encouraged to declare concrete implementations of theclosemethod to throw more specific exceptions, or to throw no exception at all if the close operation cannot fail.Cases where the close operation may fail require careful attention by implementers. It is strongly advised to relinquish the underlying resources and to internally mark the resource as closed, prior to throwing the exception. The
closemethod is unlikely to be invoked more than once and so this ensures that the resources are released in a timely manner. Furthermore it reduces problems that could arise when the resource wraps, or is wrapped, by another resource.Implementers of this interface are also strongly advised to not have the
closemethod throwInterruptedException. This exception interacts with a thread's interrupted status, and runtime misbehavior is likely to occur if anInterruptedExceptionis suppressed. More generally, if it would cause problems for an exception to be suppressed, theAutoCloseable.closemethod should not throw it.Note that unlike the
closemethod ofCloseable, thisclosemethod is not required to be idempotent. In other words, calling thisclosemethod more than once may have some visible side effect, unlikeCloseable.closewhich is required to have no effect if called more than once. However, implementers of this interface are strongly encouraged to make theirclosemethods idempotent.- Throws:
Exception- if this resource cannot be closed
Interface AutoCloseable的更多相关文章
- java.lang.AutoCloseable
java.lang.AutoCloseable和java.io.Closeable public interface AutoCloseable { void close() throws Excep ...
- JDK各个版本的新特性jdk1.5-jdk8
JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...
- Android Framework 其中A记录
一个简短的引论 以往的研究太偏应用层的功能,实现了,原则上不进入非常理解,现在,研究人员framework该框架层. 创纪录的 1.下载源代码,文件夹例如以下: 2.Android系统的层次例如以下: ...
- OutputStream类详解
主要内容包括OutputStream及其部分子类,以分析源代码的方式学习.关心的问题包括:每个字节输出流的作用,各个流之间的主要区别,何时使用某个流,区分节点流和处理流,流的输出目标等问题. Outp ...
- Java 9 揭秘(20. JDK 9中API层次的改变)
Tips 做一个终身学习的人. 在最后一章内容中,主要介绍以下内容: 下划线作为新关键字 改进使用try-with-resources块的语法 如何在匿名类中使用<>操作符 如何在接口中使 ...
- Android Framework 学习和需要学习的内容
1. 之前的研究太偏向应用层功能实现了,很多原理不了解没有深究,现在研究framework面存一些资料待有空查看. 2.Android系统的层次如下: 3.项目目录简单分析如下: 4.telphony ...
- 使用try-with-resources优雅的关闭IO流
Java类库中包括许多必须通过调用close方法来手工关闭的资源.例如InputStream.OutputStream和java.sql.Connection.客户端经常会忽略资源的关闭,造成严重的性 ...
- JDK各个版本的新特性
对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一下JDK1.5版本到JD ...
- 【新特性】JDK1.7
一.switch中可以使用字串 String s = "test";switch (s) { case "test" : System.out.printl ...
随机推荐
- yii使用bootstrap分页样式
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...
- HDU 4405: Aeroplane chess
类型:概率DP 题意:一条直线下飞行棋,色子六个面等概率.同时存在一些飞机航线,到了某个点可以直接飞到后面的另一个点,可以连飞,保证一个点至多一条航线.求到达或者超过终点 所需要 掷色子的期望次数. ...
- poj 3614(网络流)
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6672 Accepted: 2348 Descrip ...
- LeetCode OJ-- Sqrt(x) *
https://oj.leetcode.com/problems/sqrtx/ 求一个数的开方,二分查找一个数,直到这个数的平方 - target 小于 0.001. 但这道题出的不好,返回值竟然是 ...
- LeetCode OJ--Regular Expression Matching
http://oj.leetcode.com/problems/regular-expression-matching/ 问题给想复杂了,只有p中可以含有. *,s中的字符都是确定的.想了好久,最终还 ...
- CSS-滤镜 -webkit-filter
css滤镜属性,可以在元素呈现之前,为元素的渲染提供一些效果,如模糊.颜色转移之类的.滤镜常用于调整图像.背景.边框的渲染. 语法: webkit-filter: none | blur(px) | ...
- 详解Java中的字符串
字符串常量池详解 在深入学习字符串类之前, 我们先搞懂JVM是怎样处理新生字符串的. 当你知道字符串的初始化细节后, 再去写String s = "hello"或String s ...
- OS | monolithic kernel & microkernel
A monolithic kernel is a kernel where all services (file system, VFS, device drivers, etc) as well a ...
- CF997D
分析: 假设在第一个树上我们有一个长度为x的环,在第二树上我们有一个长度为y的环,那么可以在叉积树上构造出$\binom{x+y}{x}$个长度为x+y的环 问题的关键就变成了如何统计出在一个树上的长 ...
- sdut 面向对象程序设计上机练习九(对象指针)
面向对象程序设计上机练习九(对象指针) Time Limit: 1000MS Memory limit: 65536K 题目描写叙述 建立对象数组,内放5个学生数据(学号是字符串类型.成绩是整型).设 ...