{"id":1116,"date":"2014-12-04T22:43:52","date_gmt":"2014-12-04T14:43:52","guid":{"rendered":"http:\/\/coderbee.net\/?p=1116"},"modified":"2014-12-04T22:44:19","modified_gmt":"2014-12-04T14:44:19","slug":"%e8%b8%a9%e5%9d%91%e4%b9%8b-java-%e5%8f%af%e5%8f%98%e9%95%bf%e5%8f%82%e6%95%b0%e5%88%97%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/java\/20141204\/1116","title":{"rendered":"\u8e29\u5751\u4e4b  Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868"},"content":{"rendered":"<h3>Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868<\/h3>\n<p>\u8fd9\u662f Java 5 \u5f15\u5165\u7684\u4e00\u4e2a\u7279\u6027\uff0c\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u8981\u63a5\u6536\u7684\u53c2\u6570\u6570\u91cf\u662f\u4e0d\u786e\u5b9a\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7279\u6027\u5c31\u53ef\u4ee5\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n<p>\u6bd4\u5982\uff0c\u5728\u6d89\u53caIO\u64cd\u4f5c\u7684\u5730\u65b9\uff0c\u57fa\u672c\u4e0a\u81f3\u5c11\u9700\u8981\u5173\u95ed\u4e24\u4e2a\u6d41\uff1a\u8f93\u5165\u3001\u8f93\u51fa\uff0c\u6211\u559c\u6b22\u628a\u6d41\u5173\u95ed\u7684\u64cd\u4f5c\u5c01\u88c5\u6210\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u8fd9\u6837\u53ea\u9700\u4e00\u6b21\u8c03\u7528\u5c31\u53ef\u4ee5\u5173\u95ed\u591a\u4e2a\u6d41\u3002<\/p>\n<pre><code class=\"java\">public static void closeSilent(Closeable... closeables) {\n     for (Closeable closeable : closeables) {\n          if (closeable != null) {\n               try {\n                    closeable.close();\n               } catch (IOException ignored) {\n               }\n          }\n     }\n}\n<\/code><\/pre>\n<p>\u8fd9\u662f\u6211\u89c9\u5f97\u8fd9\u4e2a\u7279\u6027\u552f\u4e00\u9002\u5408\u4f7f\u7528\u7684\u5730\u65b9\uff0c\u5177\u5907\u4e0b\u9762\u7684\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\u8fd9\u4e9b\u53c2\u6570\u5177\u6709\u76f8\u540c\u7684\u7c7b\u578b\uff1b<\/li>\n<li>\u53c2\u6570\u6570\u91cf\u4e0d\u786e\u5b9a\uff0c\u6bcf\u4e00\u4e2a\u90fd\u662f\u53ef\u9009\u7684\uff1b<\/li>\n<li>\u8fd9\u4e9b\u53c2\u6570\u7684\u7528\u9014\u90fd\u662f\u4e00\u6837\u7684\uff0c\u6bd4\u5982\u4e0a\u9762\u90fd\u662f\u6267\u884c\u5173\u95ed\u3002<\/li>\n<\/ul>\n<p>Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868\u53ea\u80fd\u653e\u5728\u65b9\u6cd5\u53c2\u6570\u5217\u8868\u7684\u6700\u540e\u3002<\/p>\n<p><!--more--><\/p>\n<h4>Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868 \u7684\u5b9e\u73b0<\/h4>\n<p>Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868 \u7684\u5b9e\u73b0\u662f\u901a\u8fc7\u7f16\u8bd1\u5668\u628a\u628a\u8fd9\u4e9b\u53c2\u6570\u5c01\u88c5\u6210\u4e00\u4e2a\u6570\u7ec4\u6765\u4f20\u9012\u7684\u3002<\/p>\n<p>\u6bd4\u5982\u4e0a\u9762\u7684\u65b9\u6cd5\u7684\u7b7e\u540d\u5b9e\u9645\u4e0a\u662f\uff1a\u3000<code>closeSilent(Closeable[] closeables) void<\/code> \u3002<\/p>\n<h3>\u8e29\u5751<\/h3>\n<p>\u6709\u4e2a\u65b9\u6cd5\uff0c\u88ab A\u3001B \u4e24\u4e2a\u5730\u65b9 A\u3001B \u8c03\u7528\uff0c9 \u6708\uff0c\u5728 A \u8fd9\u91cc\u9700\u8981\u589e\u52a0\u4e00\u4e2a\u53c2\u6570\uff0c\u5f53\u65f6\u8111\u5b50\u4e00\u62bd\u75af\uff0c\u51b3\u5b9a\u7528\u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868\uff0c\u89c9\u5f97 B \u90a3\u91cc\u4e0d\u7528\u6539\u7b80\u5355\u70b9\uff0c\u5751\u5c31\u8fd9\u6837\u57cb\u4e0b\u4e86\u3002<\/p>\n<p>\u6700\u8fd1\u8981\u6c42 B \u8fd9\u91cc\u8981\u65b0\u589e\u4e24\u4e2a\u53c2\u6570\uff0c\u90a3\u5c31\u5728\u65b9\u6cd5\u7684\u53c2\u6570\u5217\u8868\u91cc\u7ee7\u7eed\u52a0\u53c2\u6570\uff0c\u8fd9\u4e9b\u53c2\u6570\u7684\u7c7b\u578b\u662f\u4e0d\u540c\u7684\uff0c\u6240\u4ee5\u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868\u58f0\u660e\u6210 Object \u7c7b\u578b\u7684\u3002<\/p>\n<p>\u7b2c\u4e00\u4e2a\u5751\u5c31\u662f\u5728\u8fd9\u4e2a\u65b9\u6cd5\u5185\u53d6\u53ef\u53d8\u957f\u53c2\u6570\u7684\u5143\u7d20\u65f6\uff0c\u6ca1\u8003\u8651\u5230\u6709\u7684\u53c2\u6570\u662f\u6ca1\u4f20\u7684\uff0c\u76f4\u63a5\u7206\u6570\u7ec4\u8d8a\u4f4d\u7684\u5f02\u5e38\u4e86\u3002\u9a6c\u4e0a\u5c31\u89c9\u5f97\u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868\u7684\u4e0d\u597d\u4e86\uff0c\u90a3\u5c31\u4e0d\u7528\u4e86\u5457\uff0c\u6539\u4e3a\u5e38\u89c4\u7684\u56fa\u5b9a\u5f62\u5f0f\u7684\u53c2\u6570\u4f20\u9012\u3002<\/p>\n<p>\u6539\u5b8c\u4e4b\u540e\uff0c\u5728\u6d4b\u8bd5\u73af\u5883\u6d4b\u4e86\u90fd\u6ca1\u95ee\u9898\u3002\u628a\u751f\u4ea7\u73af\u5883\u7684\u51e0\u4e2a\u7c7b\u66ff\u6362\u4e4b\u540e\uff0c\u7ed3\u679c\u5374\u62a5\u9519\u4e86\uff0c\u65b9\u6cd5\u627e\u4e0d\u5230\uff0c\u4e00\u770b\u65b9\u6cd5\u7b7e\u540d\uff0c\u8fd8\u662f\u6570\u7ec4\u7684\uff0c\u6ca1\u6709\u66ff\u6362\u5230\u3002\u4ece\u6e90\u7801\u770b\uff0c\u90a3\u4e2a\u8c03\u7528\u7684\u5730\u65b9\u4e0d\u9700\u8981\u66f4\u6539\uff0c\u6240\u4ee5\u6ca1\u60f3\u5230\u8981\u66ff\u6362\uff1b\u7531\u4e8e\u6d4b\u8bd5\u73af\u5883\u662f\u5168\u91cf\u6253\u5305\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n<p>\u65b9\u6cd5\u7684\u7b7e\u540d\u662f\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u5c31\u786e\u5b9a\u4e86\u7684\uff0c\u6e90\u7801\u5c42\u9762\u770b\u8d77\u6765\u4e0d\u9700\u8981\u6539\u7684\u4e0d\u8868\u793a\u7f16\u8bd1\u540e\u7684\u7c7b\u4e5f\u4e0d\u9700\u8981\u66ff\u6362\u4e86\u3002<\/p>\n<p>\u5176\u5b9e\u4ee5\u524d\u4e5f\u542c\u5230\u8fc7\uff0c\u5728\u8fd9\u79cd\u53d1\u5305\u4e0d\u89c4\u8303\u7684\u60c5\u51b5\u4e0b\uff0c\u628a\u6e90\u7801\u91cc\u7684\u4e00\u4e2a\u5e38\u91cf\u503c\u6539\u4e86\u4e4b\u540e\uff0c\u53ea\u66ff\u6362\u4e86\u8fd9\u4e2a\u5b9a\u4e49\u5e38\u91cf\u7684\u7c7b\u6587\u4ef6\uff0c\u6ca1\u6709\u628a\u6240\u6709\u5f15\u7528\u8fd9\u4e2a\u5e38\u91cf\u7684\u7c7b\u6587\u4ef6\u91cd\u65b0\u7f16\u8bd1\u66ff\u6362\uff0c\u5bfc\u81f4\u51fa\u73b0\u83ab\u540d\u5176\u5999\u7684\u95ee\u9898\u3002\u8ddf\u65b9\u6cd5\u7b7e\u540d\u7684\u60c5\u51b5\u672c\u8d28\u4e0a\u662f\u4e00\u6837\u7684\u95ee\u9898\u3002<\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u53ef\u53d8\u957f\u53c2\u6570\u5217\u8868 \u8fd9\u662f Java 5 \u5f15\u5165\u7684\u4e00\u4e2a\u7279\u6027\uff0c\u5982\u679c\u4e00\u4e2a\u65b9\u6cd5\u8981\u63a5\u6536 &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/java\/20141204\/1116\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[206],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1116"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":2,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1116\/revisions"}],"predecessor-version":[{"id":1118,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1116\/revisions\/1118"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}