{"id":456,"date":"2011-03-21T09:39:51","date_gmt":"2011-03-21T01:39:51","guid":{"rendered":"http:\/\/coderbee.net\/?p=456"},"modified":"2013-09-10T10:19:55","modified_gmt":"2013-09-10T02:19:55","slug":"finally%e8%af%ad%e5%8f%a5%e7%9a%84%e6%89%a7%e8%a1%8c%e6%97%b6%e5%88%bb","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/java\/20110321\/456","title":{"rendered":"finally\u8bed\u53e5\u7684\u6267\u884c\u65f6\u523b"},"content":{"rendered":"<p>\u4ee5\u524d\u867d\u7136\u77e5\u9053\u5728try finally\u8bed\u53e5\u4e2d\uff0c\u5373\u4f7ftry\u5757\u91cc\u6709return\u8bed\u53e5\uff0cfinally\u8bed\u53e5\u4e5f\u4f1a\u5728return\u8bed\u53e5\u6267\u884c\u4e4b\u524d\u6267\u884c\uff0c\u5374\u4e0d\u77e5\u9053return\u8868\u8fbe\u5f0f\u4e0efinally\u8bed\u53e5\u7684\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<pre><code class=\"java\">public class Test {\n    public static int a() {\n        int i = 0;\n\n        try {\n            i++;\n            return ++i;\n\n        } finally {\n            i++;\n        }\n    }\n\n    public static void main(String[] args) {\n        System.out.println(a());\n    }\n}\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u8bed\u53e5\u7684\u8f93\u51fa\u662f <code>2<\/code> \u800c\u4e0d\u662f <code>3<\/code>\u3002<br \/>\n\u5f53\u6267\u884c\u5230 <code>return ++i;<\/code><\/p>\n<p>jvm\u662f\u5148\u6267\u884c <code>++i<\/code>\uff0c\u628a\u7ed3\u679c <code>2<\/code> \u5b58\u5230\u4e34\u65f6\u53d8\u91cf\uff0c\u7136\u540e\u5728\u6267\u884cfinally\u8bed\u53e5\u91cc\u7684 <code>++i<\/code>\uff0c\u6240\u4ee5\u6700\u7ec8\u7684i\u7684\u503c\u867d\u7136\u662f <code>i<\/code>\uff0c\u4f46\u65b9\u6cd5\u8fd4\u56de\u7684\u503c\u5374\u662f <code>2<\/code>\u3002<\/p>\n<p>\u5176\u5b9e\u4ee5\u524d\u7684\u7406\u89e3\u6ca1\u6709\u9519\uff0c\u56e0\u4e3a <code>return ++i;<\/code> \u662f\u4e00\u4e2a\u590d\u5408\u8bed\u53e5\u4e86\uff0c\u76f8\u5f53\u4e8e\uff1a<\/p>\n<pre><code class=\"java\">    int j = ++i;  \n    return j;  \n<\/code><\/pre>\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>\u4ee5\u524d\u867d\u7136\u77e5\u9053\u5728try finally\u8bed\u53e5\u4e2d\uff0c\u5373\u4f7ftry\u5757\u91cc\u6709return\u8bed\u53e5\uff0cf &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/java\/20110321\/456\">\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":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/456"}],"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=456"}],"version-history":[{"count":2,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/456\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}