{"id":10008392,"date":"2024-02-23T15:33:46","date_gmt":"2024-02-23T07:33:46","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008392"},"modified":"2024-02-23T15:33:46","modified_gmt":"2024-02-23T07:33:46","slug":"%e6%b7%b1%e5%85%a5%e6%b5%85%e5%87%bajvm%ef%bc%88%e5%85%ad%ef%bc%89%e4%b9%8b%e5%89%8d%e7%ab%af%e7%bc%96%e8%af%91%e8%bf%87%e7%a8%8b%e4%b8%8e%e8%af%ad%e6%b3%95%e7%b3%96%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008392","title":{"rendered":"\u6df1\u5165\u6d45\u51faJVM\uff08\u516d\uff09\u4e4b\u524d\u7aef\u7f16\u8bd1\u8fc7\u7a0b\u4e0e\u8bed\u6cd5\u7cd6\u539f\u7406"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u5c06\u56f4\u7ed5Java\u4e2d\u7684\u7f16\u8bd1\u5668\uff0c\u6df1\u5165\u6d45\u51fa\u7684\u89e3\u6790\u524d\u7aef\u7f16\u8bd1\u7684\u6d41\u7a0b\u3001\u6cdb\u578b\u3001\u6761\u4ef6\u7f16\u8bd1\u3001\u589e\u5f3afor\u5faa\u73af\u3001\u53ef\u53d8\u957f\u53c2\u6570\u3001lambda\u8868\u8fbe\u5f0f\u7b49\u8bed\u6cd5\u7cd6\u539f\u7406<\/p>\n<h2>\u7f16\u8bd1\u5668\u4e0e\u6267\u884c\u5f15\u64ce<\/h2>\n<h3>\u7f16\u8bd1\u5668<\/h3>\n<p>Java\u4e2d\u7684\u7f16\u8bd1\u5668\u4e0d\u6b62\u4e00\u79cd\uff0cJava\u7f16\u8bd1\u5668\u53ef\u4ee5\u5206\u4e3a\uff1a<strong>\u524d\u7aef\u7f16\u8bd1\u5668\u3001\u5373\u65f6\u7f16\u8bd1\u5668\u548c\u63d0\u524d\u7f16\u8bd1\u5668<\/strong><\/p>\n<p>\u6700\u4e3a\u5e38\u89c1\u7684\u5c31\u662f<strong>\u524d\u7aef\u7f16\u8bd1\u5668javac\uff0c\u5b83\u80fd\u591f\u5c06Java\u6e90\u4ee3\u7801\u7f16\u8bd1\u4e3a\u5b57\u8282\u7801\u6587\u4ef6\uff0c\u5b83\u80fd\u591f\u4f18\u5316\u7a0b\u5e8f\u5458\u4f7f\u7528\u8d77\u6765\u5f88\u65b9\u4fbf\u7684\u8bed\u6cd5\u7cd6<\/strong><\/p>\n<p><strong>\u5373\u65f6\u7f16\u8bd1\u5668\u662f\u5728\u8fd0\u884c\u65f6\uff0c\u5c06\u70ed\u70b9\u4ee3\u7801\u76f4\u63a5\u7f16\u8bd1\u4e3a\u672c\u5730\u673a\u5668\u7801\uff0c\u800c\u4e0d\u9700\u8981\u89e3\u91ca\u6267\u884c\uff0c\u63d0\u5347\u6027\u80fd<\/strong><\/p>\n<p><strong>\u63d0\u524d\u7f16\u8bd1\u5668\u5c06\u7a0b\u5e8f\u63d0\u524d\u7f16\u8bd1\u6210\u672c\u5730\u4e8c\u8fdb\u5236\u4ee3\u7801<\/strong><\/p>\n<h3>\u524d\u7aef\u7f16\u8bd1\u8fc7\u7a0b<\/h3>\n<ul>\n<li>\u51c6\u5907\u9636\u6bb5: \u521d\u59cb\u5316\u63d2\u5165\u5f0f\u6ce8\u89e3\u5904\u7406\u5668<\/li>\n<li>\n<p>\u5904\u7406\u9636\u6bb5<\/p>\n<ul>\n<li>\n<p>\u89e3\u6790\u4e0e\u586b\u5145\u7b26\u53f7\u8868<\/p>\n<ol>\n<li>\n<p><strong>\u8bcd\u6cd5\u5206\u6790: \u5c06Java\u6e90\u4ee3\u7801\u7684\u5b57\u7b26\u6d41\u8f6c\u53d8\u4e3atoken(\u6807\u8bb0)\u6d41<\/strong><\/p>\n<ul>\n<li>\u5b57\u7b26: \u7a0b\u5e8f\u7f16\u5199\u7684\u6700\u5c0f\u5355\u4f4d<\/li>\n<li>\u6807\u8bb0(token) : \u7f16\u8bd1\u7684\u6700\u5c0f\u5355\u4f4d<\/li>\n<li>\u6bd4\u5982 \u5173\u952e\u5b57 static \u662f\u4e00\u4e2a\u6807\u8bb0 \/ 6\u4e2a\u5b57\u7b26<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8bed\u6cd5\u5206\u6790: \u5c06token\u6d41\u6784\u9020\u6210\u62bd\u8c61\u8bed\u6cd5\u6811<\/strong><\/li>\n<li>\n<p><strong>\u586b\u5145\u7b26\u53f7\u8868: \u4ea7\u751f\u7b26\u53f7\u4fe1\u606f\u548c\u7b26\u53f7\u5730\u5740<\/strong><\/p>\n<ul>\n<li>\u7b26\u53f7\u8868\u662f\u4e00\u7ec4\u7b26\u53f7\u4fe1\u606f\u548c\u7b26\u53f7\u5730\u5740\u6784\u6210\u7684\u6570\u636e\u7ed3\u6784<\/li>\n<li>\u6bd4\u5982: \u76ee\u6807\u4ee3\u7801\u751f\u6210\u9636\u6bb5\uff0c\u5bf9\u7b26\u53f7\u540d\u5206\u914d\u5730\u5740\u65f6\uff0c\u8981\u67e5\u770b\u7b26\u53f7\u8868\u4e0a\u8be5\u7b26\u53f7\u540d\u5bf9\u5e94\u7684\u7b26\u53f7\u5730\u5740<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u63d2\u5165\u5f0f\u6ce8\u89e3\u5904\u7406\u5668\u7684\u6ce8\u89e3\u5904\u7406<\/p>\n<ol start=\"4\">\n<li>\n<p><strong>\u6ce8\u89e3\u5904\u7406\u5668\u5904\u7406\u7279\u6b8a\u6ce8\u89e3: \u5728\u7f16\u8bd1\u5668\u5141\u8bb8\u6ce8\u89e3\u5904\u7406\u5668\u5bf9\u6e90\u4ee3\u7801\u4e2d\u7279\u6b8a\u6ce8\u89e3\u4f5c\u5904\u7406\uff0c\u53ef\u4ee5\u8bfb\u5199\u62bd\u8c61\u8bed\u6cd5\u6811\u4e2d\u4efb\u610f\u5143\u7d20\uff0c\u5982\u679c\u53d1\u751f\u4e86\u5199\u64cd\u4f5c\uff0c\u5c31\u8981\u91cd\u65b0\u89e3\u6790\u586b\u5145\u7b26\u53f7\u8868<\/strong><\/p>\n<ul>\n<li>\u6bd4\u5982: Lombok\u901a\u8fc7\u7279\u6b8a\u6ce8\u89e3\uff0c\u751f\u6210get\/set\/\u6784\u9020\u5668\u7b49\u65b9\u6cd5<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u8bed\u4e49\u5206\u6790\u4e0e\u5b57\u8282\u7801\u751f\u6210<\/p>\n<ol start=\"5\">\n<li>\n<p><strong>\u6807\u6ce8\u68c0\u67e5: \u5bf9\u8bed\u4e49\u9759\u6001\u4fe1\u606f\u7684\u68c0\u67e5\u4ee5\u53ca\u5e38\u91cf\u6298\u53e0\u4f18\u5316<\/strong><\/p>\n<pre><code class=\"java\">\u00a0int i = 1;\n\u00a0char c1 = 'a';\n\u00a0int i2 = 1 + 2;\/\/\u7f16\u8bd1\u6210 int i2 = 3 \u5e38\u91cf\u6298\u53e0\u4f18\u5316\n\u00a0char c2 = i + c1; \/\/\u7f16\u8bd1\u9519\u8bef \u6807\u6ce8\u68c0\u67e5 \u68c0\u67e5\u8bed\u6cd5\u9759\u6001\u4fe1\u606f <\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"99\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaM\" alt=\"image-20210524202623150.png\" title=\"image-20210524202623150.png\"><\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u53ca\u63a7\u5236\u6d41\u5206\u6790: \u5bf9\u7a0b\u5e8f\u8fd0\u884c\u65f6\u52a8\u6001\u68c0\u67e5<\/strong><\/p>\n<ul>\n<li>\u6bd4\u5982\u65b9\u6cd5\u4e2d\u6d41\u7a0b\u63a7\u5236\u4ea7\u751f\u7684\u5404\u6761\u8def\u662f\u5426\u6709\u5408\u9002\u7684\u8fd4\u56de\u503c<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u89e3\u8bed\u6cd5\u7cd6: \u5c06(\u65b9\u4fbf\u7a0b\u5e8f\u5458\u4f7f\u7528\u7684\u7b80\u6d01\u4ee3\u7801)\u8bed\u6cd5\u7cd6\u8f6c\u6362\u4e3a\u539f\u59cb\u7ed3\u6784<\/strong><\/li>\n<li><strong>\u5b57\u8282\u7801\u751f\u6210: \u751f\u6210<code>&lt;init&gt;,&lt;clinit&gt;<\/code>\u65b9\u6cd5,\u5e76\u6839\u636e\u4e0a\u8ff0\u4fe1\u606f\u751f\u6210\u5b57\u8282\u7801\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<blockquote><p>\u524d\u7aef\u7f16\u8bd1\u6d41\u7a0b\u56fe<\/p><\/blockquote>\n<p><img decoding=\"async\" width=\"723\" height=\"253\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaN\" alt=\"image-20210524205803664.png\" title=\"image-20210524205803664.png\" loading=\"lazy\"><\/p>\n<blockquote><p>\u6e90\u7801\u5206\u6790<\/p><\/blockquote>\n<p><img decoding=\"async\" width=\"723\" height=\"211\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaO\" alt=\"image-20210524222754508.png\" title=\"image-20210524222754508.png\" loading=\"lazy\"><br \/>\u4ee3\u7801\u4f4d\u7f6e\u5728JavaCompiler\u7684compile\u65b9\u6cd5\u4e2d<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"364\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaP\" alt=\"image-20210524221445424.png\" title=\"image-20210524221445424.png\" loading=\"lazy\"><\/p>\n<h3>Java\u4e2d\u7684\u8bed\u6cd5\u7cd6<\/h3>\n<h4>\u6cdb\u578b<\/h4>\n<p><strong>\u5c06\u64cd\u4f5c\u7684\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u4e3a\u65b9\u6cd5\u7b7e\u540d\u4e2d\u4e00\u79cd\u7279\u6b8a\u53c2\u6570\uff0c\u4f5c\u7528\u5728\u65b9\u6cd5\u3001\u7c7b\u3001\u63a5\u53e3\u4e0a\u65f6\u79f0\u4e3a\u6cdb\u578b\u65b9\u6cd5\u3001\u6cdb\u578b\u7c7b\u3001\u6cdb\u578b\u63a5\u53e3<\/strong><\/p>\n<p>Java\u4e2d\u7684\u6cdb\u578b\u662f<strong>\u7c7b\u578b\u64e6\u9664\u5f0f\u6cdb\u578b<\/strong>\uff0c\u6cdb\u578b\u53ea\u5728\u6e90\u4ee3\u7801\u4e2d\u5b58\u5728\uff0c<strong>\u5728\u7f16\u8bd1\u671f\u64e6\u9664\u6cdb\u578b\uff0c\u5e76\u5728\u76f8\u5e94\u7684\u5730\u65b9\u52a0\u4e0a\u5f3a\u5236\u8f6c\u6362\u4ee3\u7801<\/strong><\/p>\n<blockquote><p>\u4e0e\u5177\u73b0\u5316\u5f0f\u6cdb\u578b(\u4e0d\u4f1a\u64e6\u9664\uff0c\u8fd0\u884c\u65f6\u4e5f\u5b58\u5728\u6cdb\u578b)\u5bf9\u6bd4<\/p><\/blockquote>\n<ul>\n<li>\n<p>\u4f18\u70b9: \u53ea\u9700\u8981\u6539\u52a8\u7f16\u8bd1\u5668\uff0cJava\u865a\u62df\u673a\u548c\u5b57\u8282\u7801\u6307\u4ee4\u4e0d\u9700\u8981\u6539\u53d8<\/p>\n<ul>\n<li>\u56e0\u4e3a\u6cdb\u578b\u662fJDK5\u52a0\u5165\u7684\uff0c\u4e3a\u4e86\u6ee1\u8db3\u5bf9\u4ee5\u524d\u7248\u672c\u4ee3\u7801\u7684\u517c\u5bb9\u91c7\u7528\u7c7b\u578b\u64e6\u9664\u5f0f\u6cdb\u578b<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f3a\u70b9: \u6027\u80fd\u8f83\u4f4e\uff0c\u4f7f\u7528\u6ca1\u90a3\u4e48\u65b9\u4fbf<\/p>\n<ul>\n<li>\u4e3a\u63d0\u4f9b\u57fa\u672c\u7c7b\u578b\u7684\u6cdb\u578b\uff0c\u53ea\u80fd\u81ea\u52a8\u62c6\u88c5\u7bb1\uff0c\u5728\u76f8\u5e94\u7684\u5730\u65b9\u8fd8\u4f1a\u52a0\u901f\u5f3a\u5236\u8f6c\u6362\u4ee3\u7801\uff0c\u6240\u4ee5\u6027\u80fd\u8f83\u4f4e<\/li>\n<li>\n<p>\u8fd0\u884c\u671f\u95f4\u65e0\u6cd5\u83b7\u53d6\u5230\u6cdb\u578b\u7c7b\u578b\u4fe1\u606f<\/p>\n<ul>\n<li>\n<p>\u6bd4\u5982\u4e66\u5199\u6cdb\u578b\u7684List\u8f6c\u6570\u7ec4\u7c7b\u578b\u65f6\uff0c\u9700\u8981\u5728\u65b9\u6cd5\u7684\u53c2\u6570\u4e2d\u6307\u5b9a\u6cdb\u578b\u7c7b\u578b<\/p>\n<pre><code class=\"java\">\u00a0public static &lt;T&gt; T[] listToArray(List&lt;T&gt; list,Class&lt;T&gt; componentType){\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0T[] instance = (T[]) Array.newInstance(componentType, list.size());\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0return instance;\n\u00a0}<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u589e\u5f3afor\u5faa\u73af\u4e0e\u53ef\u53d8\u957f\u53c2\u6570<\/h4>\n<p><img decoding=\"async\" width=\"723\" height=\"339\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaQ\" alt=\"image-20210524213429033.png\" title=\"image-20210524213429033.png\" loading=\"lazy\"><\/p>\n<p>\u589e\u5f3afor\u5faa\u73af -&gt; \u8fed\u4ee3\u5668<\/p>\n<p>\u53ef\u53d8\u957f\u53c2\u6570 -&gt; \u6570\u7ec4\u88c5\u8f7d\u53c2\u6570<\/p>\n<p>\u6cdb\u578b\u64e6\u9664\u540e\u4f1a\u5728\u67d0\u4e9b\u4f4d\u7f6e\u63d2\u5165\u5f3a\u5236\u8f6c\u6362\u4ee3\u7801<\/p>\n<h4>\u81ea\u52a8\u62c6\u88c5\u7bb1<\/h4>\n<blockquote><p>\u81ea\u52a8\u88c5\u7bb1\u3001\u62c6\u7bb1\u7684\u9519\u8bef\u7528\u6cd5<\/p><\/blockquote>\n<pre><code class=\"java\">\u00a0        Integer a = 1;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Integer b = 2;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Integer c = 3;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Integer d = 3;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Integer e = 321;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Integer f = 321;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Long g = 3L;\n\u00a0        \/\/true\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(c == d);\/\/\u8303\u56f4\u5c0f\uff0c\u5728\u7f13\u51b2\u6c60\u4e2d\n\u00a0        \/\/false\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(e == f);\/\/\u8303\u56f4\u5927\uff0c\u4e0d\u5728\u7f13\u51b2\u6c60\u4e2d\uff0c\u6bd4\u8f83\u5730\u5740\u56e0\u6b64\u4e3afalse\n\u00a0        \/\/true\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(c == (a + b));\n\u00a0        \/\/true\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(c.equals(a + b));\n\u00a0        \/\/false\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(g == (b + a));\n\u00a0        \/\/true\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0System.out.println(g.equals(a + b));<\/code><\/pre>\n<ul>\n<li>\n<p>\u6ce8\u610f:<\/p>\n<ol>\n<li>\u5305\u88c5\u7c7b\u91cd\u5199\u7684equals\u65b9\u6cd5\u4e2d\u4e0d\u4f1a\u81ea\u52a8\u8f6c\u6362\u7c7b\u578b<br \/><img decoding=\"async\" width=\"723\" height=\"107\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaR\" alt=\"image-20210524213853321.png\" title=\"image-20210524213853321.png\" loading=\"lazy\"><\/li>\n<li>\u5305\u88c5\u7c7b\u7684 == \u5c31\u662f\u53bb\u6bd4\u8f83\u5f15\u7528\u5730\u5740\uff0c\u4e0d\u4f1a\u81ea\u52a8\u62c6\u7bb1<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h4>\u6761\u4ef6\u7f16\u8bd1<\/h4>\n<p>\u5e03\u5c14\u7c7b\u578b + if\u8bed\u53e5 : <strong>\u6839\u636e\u5e03\u5c14\u503c\u7c7b\u578b\u7684\u771f\u5047\uff0c\u7f16\u8bd1\u5668\u4f1a\u628a\u5206\u652f\u4e2d\u4e0d\u6210\u7acb\u7684\u4ee3\u7801\u5757\u6d88\u9664\uff08\u89e3\u8bed\u6cd5\u7cd6\uff09<\/strong><\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"304\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaS\" alt=\"image-20210524214427206.png\" title=\"image-20210524214427206.png\" loading=\"lazy\"><\/p>\n<h4>Lambda\u539f\u7406<\/h4>\n<blockquote><p>\u7f16\u5199\u51fd\u6570\u5f0f\u63a5\u53e3<\/p><\/blockquote>\n<pre><code class=\"java\">\u00a0@FunctionalInterface\n\u00a0interface LambdaTest {\n\u00a0 \u00a0 \u00a0void lambda();\n\u00a0}<\/code><\/pre>\n<blockquote><p>\u7f16\u5199\u6d4b\u8bd5\u7c7b<\/p><\/blockquote>\n<pre><code class=\"java\">\u00a0public class Lambda {\n\u00a0 \u00a0 \u00a0private int i = 10;\n\u00a0\u200b\n\u00a0 \u00a0 \u00a0public static void main(String[] args) {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0test(() -&gt; System.out.println(&quot;\u533f\u540d\u5185\u90e8\u7c7b\u5b9e\u73b0\u51fd\u6570\u5f0f\u63a5\u53e3&quot;));\n\u00a0 \u00a0  }\n\u00a0\u200b\n\u00a0 \u00a0 \u00a0public static void test(LambdaTest lambdaTest) {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0lambdaTest.lambda();\n\u00a0 \u00a0  }\n\u00a0}<\/code><\/pre>\n<blockquote><p>\u4f7f\u7528\u63d2\u4ef6\u67e5\u770b\u5b57\u8282\u7801\u6587\u4ef6<\/p><\/blockquote>\n<p><img decoding=\"async\" width=\"723\" height=\"288\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaT\" alt=\"image-20210524230643123.png\" title=\"image-20210524230643123.png\" loading=\"lazy\"><br \/>\u751f\u6210\u4e86\u4e00\u4e2a\u79c1\u6709\u9759\u6001\u7684\u65b9\u6cd5,\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u5f88\u660e\u663e\u5c31\u662flambda\u4e2d\u7684\u4ee3\u7801<\/p>\n<p><strong>\u5728\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u7684\u7c7b\u4e2d\u9690\u5f0f\u751f\u6210\u4e00\u4e2a\u9759\u6001\u79c1\u6709\u7684\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u4ee3\u7801\u5757\u5c31\u662flambda\u8868\u8fbe\u5f0f\u4e2d\u5199\u7684\u4ee3\u7801<\/strong><\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"261\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaU\" alt=\"image-20210524232010510.png\" title=\"image-20210524232010510.png\" loading=\"lazy\"><br \/>\u6267\u884cclass\u6587\u4ef6\u65f6\u5e26\u4e0a\u53c2\u6570<code>java -Djdk.internal.lambda.dumpProxyClasses \u5305\u540d.\u7c7b\u540d<\/code>\u5373\u53ef\u663e\u793a\u51fa\u8fd9\u4e2a\u533f\u540d\u5185\u90e8\u7c7b<\/p>\n<p><img decoding=\"async\" width=\"711\" height=\"342\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbwaV\" alt=\"image-20210527083659256.png\" title=\"image-20210527083659256.png\" loading=\"lazy\"><\/p>\n<p><strong>\u4f7f\u7528<code>invokedynamic<\/code>\u751f\u6210\u4e86\u4e00\u4e2a\u5b9e\u73b0\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u533f\u540d\u5185\u90e8\u7c7b\u5bf9\u8c61\uff0c\u5728\u91cd\u5199\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u65b9\u6cd5\u5b9e\u73b0\u4e2d\u8c03\u7528\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u7c7b\u4e2d\u9690\u5f0f\u751f\u6210\u7684\u9759\u6001\u79c1\u6709\u65b9\u6cd5<\/strong><\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u672c\u7bc7\u6587\u7ae0\u4ee5Java\u4e2d\u7f16\u8bd1\u5668\u7684\u5206\u7c7b\u4e3a\u5f00\u7bc7\uff0c\u6df1\u5165\u6d45\u51fa\u7684\u89e3\u6790\u524d\u7aef\u7f16\u8bd1\u7684\u6d41\u7a0b\uff0cJava\u4e2d\u6cdb\u578b\u3001\u589e\u5f3afor\u5faa\u73af\u3001\u53ef\u53d8\u957f\u53c2\u6570\u3001\u81ea\u52a8\u62c6\u88c5\u7bb1\u3001\u6761\u4ef6\u7f16\u8bd1\u4ee5\u53caLambda\u7b49\u8bed\u6cd5\u7cd6\u7684\u539f\u7406<\/p>\n<p><strong>\u524d\u7aef\u7f16\u8bd1\u5148\u5c06\u5b57\u7b26\u6d41\u8f6c\u6362\u4e3atoken\u6d41\uff0c\u518d\u5c06token\u6d41\u8f6c\u6362\u4e3a\u62bd\u8c61\u8bed\u6cd5\u6811\uff0c\u586b\u5145\u7b26\u53f7\u8868\u7684\u7b26\u53f7\u4fe1\u606f\u3001\u7b26\u53f7\u5730\u5740\uff0c\u7136\u540e\u6ce8\u89e3\u5904\u7406\u5668\u5904\u7406\u7279\u6b8a\u6ce8\u89e3\uff08\u6bd4\u5982Lombok\u751f\u6210get\u3001set\u65b9\u6cd5\uff09\uff0c\u5bf9\u8bed\u6cd5\u6811\u53d1\u751f\u5199\u6539\u52a8\u5219\u8981\u91cd\u65b0\u89e3\u6790\u3001\u586b\u5145\u7b26\u53f7\uff0c\u63a5\u7740\u68c0\u67e5\u8bed\u4e49\u9759\u6001\u4fe1\u606f\u4ee5\u53ca\u5e38\u91cf\u6298\u53e0\uff0c\u5bf9\u8fd0\u884c\u65f6\u7a0b\u5e8f\u8fdb\u884c\u52a8\u6001\u68c0\u67e5\uff0c\u518d\u89e3\u8bed\u6cd5\u7cd6\uff0c\u751f\u6210init\u5b9e\u4f8b\u65b9\u6cd5\u3001clinit\u9759\u6001\u65b9\u6cd5\uff0c\u6700\u540e\u751f\u6210\u5b57\u8282\u7801\u6587\u4ef6<\/strong><\/p>\n<p><strong>Java\u4e2d\u4e3a\u4e86\u517c\u5bb9\u4e4b\u524d\u7684\u7248\u672c\u4f7f\u7528\u7c7b\u578b\u64e6\u9664\u5f0f\u7684\u6cdb\u578b\uff0c\u5728\u7f16\u8bd1\u671f\u95f4\u64e6\u9664\u6cdb\u578b\u5e76\u5728\u76f8\u5e94\u4f4d\u7f6e\u52a0\u4e0a\u5f3a\u5236\u8f6c\u6362\uff0c\u60f3\u4e3a\u57fa\u672c\u7c7b\u578b\u4f7f\u7528\u6cdb\u578b\u53ea\u80fd\u642d\u914d\u81ea\u52a8\u62c6\u88c5\u7bb1\u4e00\u8d77\u4f7f\u7528\uff0c\u6027\u80fd\u6709\u635f\u8017\u4e14\u5728\u8fd0\u884c\u65f6\u65e0\u6cd5\u83b7\u53d6\u6cdb\u578b\u7c7b\u578b<\/strong><\/p>\n<p><strong>\u589e\u52a0for\u5faa\u73af\u5219\u662f\u4f7f\u7528\u8fed\u4ee3\u5668\u5b9e\u73b0\uff0c\u5e76\u5728\u9002\u5f53\u4f4d\u7f6e\u63d2\u5165\u5f3a\u5236\u8f6c\u6362\uff1b\u53ef\u53d8\u957f\u53c2\u6570\u5219\u662f\u521b\u5efa\u6570\u7ec4\u8fdb\u884c\u88c5\u8f7d\u53c2\u6570<\/strong><\/p>\n<p><strong>\u81ea\u52a8\u62c6\u88c5\u7bb1\u63d0\u4f9b\u57fa\u672c\u7c7b\u578b\u4e0e\u5305\u88c5\u7c7b\u7684\u8f6c\u6362\uff0c\u4f46\u5305\u88c5\u7c7b\u5c3d\u91cf\u4e0d\u4f7f\u7528==\uff0c\u8fd9\u662f\u53bb\u6bd4\u8f83\u5f15\u7528\u5730\u5740\uff0c\u540c\u7c7b\u578b\u6bd4\u8f83\u4f7f\u7528equals<\/strong><\/p>\n<p><strong>\u6761\u4ef6\u7f16\u8bd1\u4f1a\u5728if-else\u8bed\u53e5\u4e2d\u6839\u636e\u5e03\u5c14\u7c7b\u578b\u5c06\u4e0d\u6210\u7acb\u7684\u5206\u652f\u4ee3\u7801\u5757\u6d88\u9664<\/strong><\/p>\n<p><strong>lambda\u539f\u7406\u5219\u662f\u901a\u8fc7<code>invokeDynamic<\/code>\u6307\u4ee4\u52a8\u6001\u751f\u6210\u5b9e\u73b0\u51fd\u6570\u5f0f\u63a5\u53e3\u7684\u533f\u540d\u5bf9\u8c61\uff0c\u533f\u540d\u5bf9\u8c61\u91cd\u5199\u51fd\u6570\u65f6\u63a5\u53e3\u65b9\u6cd5\u4e2d\u8c03\u7528\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u7c7b\u4e2d\u9690\u5f0f\u751f\u6210\u7684\u9759\u6001\u79c1\u6709\u7684\u65b9\u6cd5\uff08\u8be5\u65b9\u6cd5\u5c31\u662flambda\u8868\u8fbe\u5f0f\u4e2d\u7684\u4ee3\u7801\u5185\u5bb9\uff09<\/strong><\/p>\n<h3>\u6700\u540e\uff08\u4e0d\u8981\u767d\u5ad6\uff0c\u4e00\u952e\u4e09\u8fde\u6c42\u6c42\u62c9\/~\uff09<\/h3>\n<p>\u672c\u7bc7\u6587\u7ae0\u7b14\u8bb0\u4ee5\u53ca\u6848\u4f8b\u88ab\u6536\u5165 <a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=4yHNom3Eqg9o%2FO69Rlp30g%3D%3D.xJ%2FSCNUl4ve4CSvRK9hafGMg9CtGGZNej4LdXMWKkag%2B%2FMHdL86%2Fi5PPDYfF0HtSRYrHGvSzma3k8tE6kqJITUXbuweqiHyy4Q94FtEW0QRgFP%2Fi%2Fm6B3rlO5LfGclBp\" rel=\"noopener noreferrer\">gitee-StudyJava<\/a>\u3001 <a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=GzkrL63wICo6EylnEmcHnw%3D%3D.kTfylV1VZeCV0uS0k2kqCozyeasmtjUUuXSQudFL0Wd2tSRrYFNDVnteyk7%2BE4%2Fz6hsICUG%2FqxMauBxsLYs1n8B4LDb8nPpjMm8AQ%2BIK2Oo%3D\" rel=\"noopener noreferrer\">github-StudyJava<\/a> \u611f\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5stat\u4e0b\u6301\u7eed\u5173\u6ce8\u5594\/~<\/p>\n<p>\u6709\u4ec0\u4e48\u95ee\u9898\u53ef\u4ee5\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\uff0c\u5982\u679c\u89c9\u5f97\u83dc\u83dc\u5199\u7684\u4e0d\u9519\uff0c\u53ef\u4ee5\u70b9\u8d5e\u3001\u5173\u6ce8\u3001\u6536\u85cf\u652f\u6301\u4e00\u4e0b\/~<\/p>\n<p>\u5173\u6ce8\u83dc\u83dc\uff0c\u5206\u4eab\u66f4\u591a\u5e72\u8d27\uff0c\u516c\u4f17\u53f7\uff1a\u83dc\u83dc\u7684\u540e\u7aef\u79c1\u623f\u83dc<\/p>\n<blockquote><p>\u672c\u6587\u7531\u535a\u5ba2\u4e00\u6587\u591a\u53d1\u5e73\u53f0 <a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=7Ox6kNbqcZjJBinVboXmBA%3D%3D.hR5oJUQTIRRFlOqrCs3GonDPTTSaxS2sLtHGGoSVLZjIpEIGG3nx1%2B9d%2Bhys1IbQ\" rel=\"noopener noreferrer\">OpenWrite<\/a> \u53d1\u5e03\uff01<\/p><\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044651952\">https:\/\/segmentfault.com\/a\/1190000044651952<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u5c06\u56f4\u7ed5Java\u4e2d\u7684\u7f16\u8bd1\u5668\uff0c\u6df1\u5165\u6d45\u51fa\u7684\u89e3\u6790\u524d\u7aef\u7f16\u8bd1\u7684\u6d41\u7a0b\u3001\u6cdb\u578b\u3001\u6761\u4ef6\u7f16\u8bd1\u3001\u589e\u5f3afor\u5faa\u73af\u3001\u53ef\u53d8\u957f\u53c2\u6570\u3001l [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008392","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008392"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008392\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}