码迷,mamicode.com
首页 > 编程语言 > 详细

Java中的 try(){}

时间:2021-03-15 10:48:51      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:包括   class   manage   ini   targe   must   关闭   detail   input   


参考:https://blog.csdn.net/qq_33543634/article/details/80725899


从网上查阅资料得知从 Java 7 build 105 版本开始,Java 7 的编译器和运行环境支持新的 try-with-resources 语句,称为 ARM 块(Automatic Resource Management) ,自动资源管理:

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.

谷歌翻译:

try-with-resources语句是声明一个或多个资源的try语句。 资源是一个对象,程序完成后必须将其关闭。 try-with-resources语句可确保在语句末尾关闭每个资源。 任何实现java.lang.AutoCloseable的对象(包括所有实现java.io.Closeable的对象)都可以用作资源。


//src
public abstract class InputStream implements Closeable {

    // MAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to
    // use when skipping.
    private static final int MAX_SKIP_BUFFER_SIZE = 2048;

    
    //...
}

Java中的 try(){}

标签:包括   class   manage   ini   targe   must   关闭   detail   input   

原文地址:https://www.cnblogs.com/gyjjj/p/14526507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!