为什么try-with-resource优于try-catch-finally
为什么try-with-resource优于try-catch-finally
一、Effective Java 学习心得
1、学习了Java中的终结方法,建议是在日常开发中不要使用终结方法。
2、了解了try-with-resource语法糖(在jdk1.7引入)它让我们关闭资源不用嵌套在一层层的finally块中,比try-catch-finally靠谱(可能会产生异常屏蔽)。要使用try-with-resource的资源,必须先实现AutoCloseable接口,其中包含了单个返回void的close
原创
2021-06-16 22:13:52 ·
190 阅读 ·
0 评论