java中带参数的try(){}语法含义是什么?

原文链接:https://blog.csdn.net/llkoio/article/details/78939148

带资源的try语句(try-with-resource)的最简形式为:

 
try(Resource res = xxx)//可指定多个资源
 
{
 
work with res
 
}

try块退出时,会自动调用res.close()方法,关闭资源。

 

PS:在coreJava第9版的第一卷的486页有解释。

posted @ 2020-10-13 09:32  超级珍贵  阅读(732)  评论(0编辑  收藏  举报