{"id":5712,"date":"2026-05-13T19:18:54","date_gmt":"2026-05-13T11:18:54","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=5712"},"modified":"2026-05-13T19:18:54","modified_gmt":"2026-05-13T11:18:54","slug":"jdk-27-%e5%8f%88%e6%8a%8a-api-%e7%a0%8d%e4%ba%86%e4%bf%a9%e6%96%b9%e6%b3%95%ef%bc%8cjep-531-%e5%92%8c-set-oflazy-%e6%9d%a5%e4%ba%86","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=5712","title":{"rendered":"JDK 27 \u53c8\u628a API \u780d\u4e86\u4fe9\u65b9\u6cd5\uff0cJEP 531 \u548c Set.ofLazy() \u6765\u4e86"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5927\u7ea6 1 \u4e2a\u6708\u4e4b\u524d\uff0c\u6211\u5199\u4e86\u4e00\u7bc7\u5173\u4e8e JDK 27 \u7684\u6587\u7ae0\uff0c\u5f53\u65f6\u7684 JDK 27 \u8fd8\u53ea\u6709\u4e00\u4e2a JEP\u3002\u73b0\u5728\uff0c\u968f\u7740\u65f6\u95f4\u7684\u63a8\u8fdb\uff0c\u53c8\u52a0\u5165\u4e86\u4e00\u4e9b JEP\u3002\u4f46\u662f\u8fd9\u4e9b JEP \u5462\uff0c\u4e0d\u51fa\u610f\u5916\u90fd\u662f\u7ecf\u8fc7\u591a\u8f6e\u9884\u89c8\u7684 JEP\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u53f7\u867d\u7136\u662f\u65b0\u7684\uff0c\u4f46\u5b83\u4eec\u672c\u8eab\u6539\u8fdb\u6216\u6539\u52a8\u5e76\u4e0d\u5927\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u60f0\u6027\u5e38\u91cf\u4e3a\u4f8b\uff0c\u6211\u4eca\u5929\u770b\u5230 JDK 27 \u5df2\u7ecf\u52a0\u5165\u4e86 JEP 531\uff0c\u8fd9\u4e0d\u5c31\u662f\u60f0\u6027\u5e38\u91cf\u7684\u7b2c\u4e09\u6b21\u9884\u89c8\uff0c\u4ec0\u4e48\u65f6\u5019\u80fd\u771f\u6b63 release \u5462\uff1f\u800c\u4e14\u4e3a\u4ec0\u4e48\u53c8\u6539\u4e86\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u5927\u81f4\u770b\u4e86\u4e00\u773c\uff0c<code>https:\/\/openjdk.org\/jeps\/531<\/code>\uff0c\u603b\u7ed3\u51fa\u4e86\u4e00\u53e5\u3002\u90a3\u5c31\u662f\uff0cJEP 531 \u662f JDK 27 \u4e2d\u60f0\u6027\u5e38\u91cf\u7684\u7b2c\u4e09\u6b21\u9884\u89c8\uff0c\u5b83\u4ece JDK 26 \u7684 JEP 526 \u201c\u6362\u53f7\u201d\u800c\u6765\uff0c\u6838\u5fc3\u53d8\u5316\u662f<code>\u505a\u51cf\u6cd5<\/code>\uff0c\u79fb\u9664 <code>isInitialized()<\/code> \u548c <code>orElse()<\/code> \u4e24\u4e2a\u65b9\u6cd5\uff1b\u540c\u65f6\u53c8<code>\u505a\u52a0\u6cd5<\/code>\uff0c\u65b0\u589e <code>Set.ofLazy()<\/code> \u5de5\u5382\u65b9\u6cd5\uff0c\u8865\u5168\u4e86\u4e09\u5927\u57fa\u7840\u96c6\u5408\u7c7b\u578b\u7684\u60f0\u6027\u652f\u6301\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\uff0c\u5c31\u5c55\u5f00\u8bf4\u4e00\u8bf4\uff0c\u8fd9\u6b21\u9884\u89c8\u4ee5\u53ca\u8fd9\u8fd9\u5176\u4e2d\u53d8\u66f4\u7684\u89e3\u6790\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u4ece 526 \u53d8\u6210\u4e86 531\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f88\u591a\u5f00\u53d1\u8005\u770b\u5230 JEP 531 \u7684\u6587\u6863\u65f6\u4f1a\u6ce8\u610f\u5230\u4e00\u4e2a\u7ec6\u8282\uff1a\u5b83\u660e\u786e\u5199\u7740<code>This API first previewed in JDK 25 via JEP 502... re-previewed in JDK 26 via JEP 526... we here propose to revise and re-preview the API in JDK 27<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u5c31\u662f\u8bf4\uff0c<code>\u540c\u4e00\u4e2a\u7279\u6027\uff0c\u4e09\u6b21\u9884\u89c8\uff0c\u4e09\u4e2a\u4e0d\u540c\u7684 JEP \u7f16\u53f7<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5176\u5b9e\u662f OpenJDK \u7684<code>\u6807\u51c6\u64cd\u4f5c\u6d41\u7a0b<\/code>\u3002JEP\uff08Java Enhancement Proposal\uff09\u672c\u8d28\u4e0a\u662f\u4e00\u4efd\u201c\u8bbe\u8ba1\u63d0\u6848\u6587\u6863\u201d\uff0c\u6bcf\u6b21\u5bf9 API \u8fdb\u884c<code>\u5b9e\u8d28\u6027\u4fee\u8ba2<\/code>\u5e76\u91cd\u65b0\u8fdb\u5165\u9884\u89c8\u9636\u6bb5\u65f6\uff0c\u901a\u5e38\u90fd\u4f1a\u5206\u914d\u4e00\u4e2a\u65b0\u7684 JEP \u7f16\u53f7\u3002JDK 25 \u7684 JEP 502 \u9996\u6b21\u9884\u89c8\u65f6\u5b83\u8fd8\u53eb <code>StableValue<\/code>\uff1bJDK 26 \u7684 JEP 526 \u8fdb\u884c\u4e86\u5927\u89c4\u6a21\u91cd\u6784\uff0c\u6539\u540d <code>LazyConstant<\/code>\u3001\u79fb\u9664\u4f4e\u5c42\u65b9\u6cd5\u3001\u5c06\u5de5\u5382\u65b9\u6cd5\u79fb\u5165 <code>List<\/code>\/<code>Map<\/code> \u63a5\u53e3\u3001\u7981\u6b62 <code>null<\/code> \u503c\uff1b\u5230\u4e86 JDK 27\uff0c\u518d\u6b21\u4fee\u8ba2\u540e\u53c8\u6709\u4e86\u65b0\u7684\u7f16\u53f7 JEP 531\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\uff0c<code>JEP \u7f16\u53f7\u7684\u53d8\u66f4\u4e0d\u4ee3\u8868\u7279\u6027\u88ab\u5e9f\u5f03\uff0c\u800c\u662f\u4ee3\u8868\u8fd9\u4e2a\u7279\u6027\u5728\u6301\u7eed\u8fed\u4ee3\u4e2d<\/code>\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u4e3a\u201c\u540c\u4e00\u4e2a\u7279\u6027\u7684 2.0\u30013.0 \u7248\u672c\u6587\u6863\u201d\uff0c\u6216\u8005\u662f\u540c\u4e00\u4e2a\u7279\u6027\u7684\u591a\u6b21\u8fed\u4ee3\u7684\u7248\u672c\u53f7\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e09\u6b21\u9884\u89c8\u7684\u6838\u5fc3\u53d8\u5316<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u6765\u8bf4\uff0c\u5c31\u662f\u505a\u51cf\u6cd5\u53c8\u505a\u52a0\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6587\u7ae0\u914d\u56fe\u53c2\u89c1 <a href=\"https:\/\/mp.weixin.qq.com\/s\/tXjFe9Oce2dDS59_TAsuLg\">https:\/\/mp.weixin.qq.com\/s\/tXjFe9Oce2dDS59_TAsuLg<\/a>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u79fb\u9664 isInitialized\u3001orElse<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 JDK 26 \u7684\u7b2c\u4e8c\u6b21\u9884\u89c8\u4e2d\uff0c<code>LazyConstant<\/code> \u63a5\u53e3\u63d0\u4f9b\u4e86\u4e09\u4e2a\u65b9\u6cd5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>get()<\/code>\uff1a\u83b7\u53d6\u503c\uff0c\u82e5\u672a\u521d\u59cb\u5316\u5219\u89e6\u53d1\u8ba1\u7b97<\/li><li><code>isInitialized()<\/code>\uff1a\u67e5\u8be2\u662f\u5426\u5df2\u521d\u59cb\u5316\uff08\u4e0d\u89e6\u53d1\u8ba1\u7b97\uff09<\/li><li><code>orElse(T other)<\/code>\uff1a\u82e5\u5df2\u521d\u59cb\u5316\u8fd4\u56de\u503c\uff0c\u5426\u5219\u8fd4\u56de\u9ed8\u8ba4\u503c\uff08\u4e0d\u89e6\u53d1\u8ba1\u7b97\uff09<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5230\u4e86 JDK 27 \u7684 JEP 531\uff0c<code>\u540e\u4e24\u4e2a\u65b9\u6cd5\u88ab\u5f7b\u5e95\u79fb\u9664<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b98\u65b9\u7ed9\u51fa\u7684\u7406\u7531\u662f\uff1a<code>as these could be used in ways not consistent with the design goals of the API<\/code>\u3002\u7ffb\u8bd1\u8fc7\u6765\u5c31\u662f\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u7684\u4f7f\u7528\u65b9\u5f0f\u4e0e API \u7684\u8bbe\u8ba1\u76ee\u6807\u4e0d\u4e00\u81f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f0\u6027\u5e38\u91cf\u7684\u6838\u5fc3\u8bbe\u8ba1\u54f2\u5b66\u662f\u201c\u5ef6\u8fdf\u4e0d\u53d8\u6027\u201d\uff08Deferred Immutability\uff09\uff1a\u4e00\u4e2a\u503c\u5728\u9996\u6b21\u8bbf\u95ee\u524d\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u4e00\u65e6\u521d\u59cb\u5316\u5c31\u6c38\u8fdc\u4e0d\u53d8\uff0c\u4e14\u521d\u59cb\u5316\u8fc7\u7a0b\u5bf9\u7528\u6237\u5e94\u8be5\u662f\u900f\u660e\u7684\u3002<code>get()<\/code> \u65b9\u6cd5\u5b8c\u7f8e\u4f53\u73b0\u4e86\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u5173\u5fc3\u5b83\u662f\u5426\u5df2\u7ecf\u521d\u59cb\u5316\uff0c\u8c03\u7528\u5b83\u5c31\u80fd\u5f97\u5230\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46 <code>isInitialized()<\/code> \u548c <code>orElse()<\/code> \u5374<code>\u6253\u7834\u4e86\u8fd9\u79cd\u900f\u660e\u6027<\/code>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>isInitialized()<\/code> \u8ba9\u4f60\u53ef\u4ee5\u201c\u7aa5\u89c6\u201d\u5185\u90e8\u72b6\u6001\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u4ee3\u7801\u4e2d\u51fa\u73b0\u5206\u652f\u903b\u8f91\uff1a<code>if (lc.isInitialized()) { ... } else { ... }<\/code>\u3002\u8fd9\u79cd\u5199\u6cd5\u5b9e\u9645\u4e0a\u662f\u5728\u201c\u624b\u52a8\u7ba1\u7406\u521d\u59cb\u5316\u72b6\u6001\u201d\uff0c\u4e0e\u60f0\u6027\u5e38\u91cf\u201c\u81ea\u52a8\u3001\u900f\u660e\u3001\u81f3\u591a\u4e00\u6b21\u201d\u7684\u8bbe\u8ba1\u521d\u8877\u76f8\u8fdd\u80cc\u3002<\/li><li><code>orElse()<\/code> \u63d0\u4f9b\u4e86\u201c\u5982\u679c\u8fd8\u6ca1\u521d\u59cb\u5316\u5c31\u7528\u522b\u7684\u503c\u201d\u7684\u8bed\u4e49\uff0c\u8fd9\u672c\u8d28\u4e0a\u662f\u5728\u9f13\u52b1\u201c\u975e\u786e\u5b9a\u6027\u7684\u7f16\u7a0b\u6a21\u5f0f\u201d\uff0c\u8c03\u7528\u8005\u9700\u8981\u4e3a\u4e00\u4e2a\u53ef\u80fd\u5c1a\u672a\u521d\u59cb\u5316\u7684\u5e38\u91cf\u51c6\u5907\u5907\u9009\u65b9\u6848\uff0c\u8fd9\u4f1a\u8ba9\u4ee3\u7801\u903b\u8f91\u53d8\u5f97\u590d\u6742\u4e14\u96be\u4ee5\u63a8\u7406\u3002<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u793e\u533a\u4e2d\u4e5f\u6709\u5f00\u53d1\u8005\u8ba8\u8bba\u8ba4\u4e3a\uff0c\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u5bb9\u6613\u8ba9\u4eba\u628a <code>LazyConstant<\/code> \u5f53\u6210\u201c\u5e26\u7f13\u5b58\u7684 Optional\u201d\u6765\u7528\uff0c\u800c\u5b83\u7684\u771f\u6b63\u5b9a\u4f4d\u5e94\u8be5\u662f\u201c\u53ef\u4ee5\u5ef6\u8fdf\u521d\u59cb\u5316\u7684 final \u5b57\u6bb5\u201d\u3002\u79fb\u9664\u8fd9\u4e24\u4e2a\u65b9\u6cd5\uff0c\u5c31\u662f\u5728<code>\u5f3a\u5236\u5f00\u53d1\u8005\u56de\u5f52\u7b80\u5355\u3001\u7eaf\u7cb9\u7684\u5e38\u91cf\u8bed\u4e49<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b0\u589e Set.ofLazy()<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JDK 26 \u7684\u7b2c\u4e8c\u6b21\u9884\u89c8\u5f15\u5165\u4e86 <code>List.ofLazy()<\/code> \u548c <code>Map.ofLazy()<\/code>\uff0c\u8ba9\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u53ef\u4ee5\u72ec\u7acb\u60f0\u6027\u521d\u59cb\u5316\uff0c\u4f46 <code>Set<\/code> \u7c7b\u578b\u5f53\u65f6\u7f3a\u5e2d\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JEP 531 \u65b0\u589e\u4e86 <code>Set.ofLazy()<\/code>\uff0c\u81f3\u6b64 Java \u4e09\u5927\u57fa\u7840\u96c6\u5408\u7c7b\u578b\uff08<code>List<\/code>\u3001<code>Set<\/code>\u3001<code>Map<\/code>\uff09\u90fd\u6709\u4e86\u5bf9\u5e94\u7684\u60f0\u6027\u5de5\u5382\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b98\u65b9\u7ed9\u51fa\u7684\u5178\u578b\u7528\u4f8b\u662f<code>\u914d\u7f6e\u9009\u9879\u7684\u60f0\u6027\u5224\u5b9a<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Application {\n    enum Option { VERBOSE, DRY_RUN, STRICT }\n\n    \/\/ \u6bcf\u4e2a\u9009\u9879\u662f\u5426\u542f\u7528\uff0c\u9996\u6b21\u67e5\u8be2\u65f6\u624d\u6267\u884c\u6602\u8d35\u7684\u5224\u5b9a\u903b\u8f91\n    static final Set&lt;Option&gt; OPTIONS =\n        Set.ofLazy(EnumSet.allOf(Option.class), Application::isEnabled);\n\n    private static boolean isEnabled(Option option) {\n        \/\/ \u89e3\u6790\u547d\u4ee4\u884c\u3001\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u3001\u67e5\u8be2\u6570\u636e\u5e93...\n        return ...;\n    }\n\n    public static void process() {\n        if (OPTIONS.contains(Option.DRY_RUN)) {\n            return; \/\/ \u53ea\u6709 DRY_RUN \u88ab\u67e5\u8be2\u65f6\uff0c\u624d\u4f1a\u89e6\u53d1 isEnabled(DRY_RUN)\n        }\n        \/\/ ...\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u4f8b\u5b50\u975e\u5e38\u7cbe\u5999\uff1a<code>Set.ofLazy()<\/code> \u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff0c\u4e00\u4e2a\u9884\u5b9a\u4e49\u7684\u5143\u7d20\u5019\u9009\u96c6\uff08\u8fd9\u91cc\u662f\u6240\u6709\u679a\u4e3e\u503c\uff09\uff0c\u4ee5\u53ca\u4e00\u4e2a\u5224\u5b9a\u51fd\u6570\u3002\u96c6\u5408\u4e2d\u7684<code>\u6bcf\u4e2a\u5143\u7d20\u7684\u6210\u5458\u8d44\u683c<\/code>\u90fd\u5b58\u50a8\u5728\u4e00\u4e2a\u72ec\u7acb\u7684 <code>LazyConstant<\/code> \u4e2d\uff0c\u9996\u6b21 <code>contains()<\/code> \u67e5\u8be2\u65f6\u624d\u8ba1\u7b97\u8be5\u5143\u7d20\u662f\u5426\u5c5e\u4e8e\u96c6\u5408\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e5f\u610f\u5473\u7740\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5982\u679c\u6211\u4eec\u53ea\u67e5\u8be2 <code>DRY_RUN<\/code>\uff0c\u5176\u4ed6\u9009\u9879\u7684\u5224\u5b9a\u903b\u8f91<code>\u6c38\u8fdc\u4e0d\u4f1a\u6267\u884c<\/code><\/li><li>\u6bcf\u4e2a\u9009\u9879\u7684\u5224\u5b9a\u7ed3\u679c<code>\u81f3\u591a\u8ba1\u7b97\u4e00\u6b21<\/code><\/li><li>\u521d\u59cb\u5316\u540e\u7684\u7ed3\u679c\u53ef\u4ee5\u88ab JVM <code>\u5e38\u91cf\u6298\u53e0\u4f18\u5316<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">API \u7684\u4e09\u5e74\u8fdb\u5316\u53f2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u201c\u7a33\u5b9a\u503c\u201d\u5230\u201c\u60f0\u6027\u5e38\u91cf\u201d\uff0c\u5305\u542b\u4e86\u8fd9\u4e2a API \u7684\u4e09\u5e74\u8fdb\u5316\u53f2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u987e\u8fd9\u4e2a\u7279\u6027\u7684\u6f14\u8fdb\uff0c\u6211\u4eec\u80fd\u6e05\u6670\u770b\u5230 OpenJDK \u56e2\u961f<code>\u4ece\u4f4e\u5c42\u673a\u5236\u5230\u9ad8\u5c42\u62bd\u8c61<\/code>\u7684\u8bbe\u8ba1\u601d\u8def\u8f6c\u53d8\u3002<\/p>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>\u9636\u6bb5<\/th><th>JDK \u7248\u672c<\/th><th>JEP \u7f16\u53f7<\/th><th>\u540d\u79f0<\/th><th>\u6838\u5fc3\u53d8\u5316<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u6b21\u9884\u89c8<\/td><td>JDK 25<\/td><td>JEP 502<\/td><td>Stable Values<\/td><td>\u4f4e\u5c42 API\uff0c\u63d0\u4f9b <code>orElseSet<\/code>\u3001<code>setOrThrow<\/code>\u3001<code>trySet<\/code> \u7b49\u5e95\u5c42\u63a7\u5236\u65b9\u6cd5<\/td><\/tr><tr><td>\u7b2c\u4e8c\u6b21\u9884\u89c8<\/td><td>JDK 26<\/td><td>JEP 526<\/td><td>Lazy Constants<\/td><td>\u5927\u91cd\u6784\uff1a\u6539\u540d\u3001\u79fb\u9664\u5e95\u5c42\u65b9\u6cd5\u3001\u5de5\u5382\u65b9\u6cd5\u79fb\u5165\u96c6\u5408\u63a5\u53e3\u3001\u7981\u6b62 <code>null<\/code><\/td><\/tr><tr><td>\u7b2c\u4e09\u6b21\u9884\u89c8<\/td><td>JDK 27<\/td><td>JEP 531<\/td><td>Lazy Constants<\/td><td>\u7cbe\u4fee\uff1a\u79fb\u9664 <code>isInitialized()<\/code>\/<code>orElse()<\/code>\uff0c\u65b0\u589e <code>Set.ofLazy()<\/code><\/td><\/tr><\/tbody><\/table>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u6b21\u8fed\u4ee3\uff0c\u4e00\u6b21\u6bd4\u4e00\u6b21<code>\u7b80\u6d01<\/code>\uff0c\u4e00\u6b21\u6bd4\u4e00\u6b21\u201c\u805a\u7126\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JDK 25 \u7684 <code>StableValue<\/code> \u66f4\u50cf\u662f\u4e00\u4e2a\u201c\u5e76\u53d1\u539f\u8bed\u5de5\u5177\u7bb1\u201d\uff1b\u5230\u4e86 JDK 26\uff0c\u5b83\u53d8\u6210\u4e86\u201c\u60f0\u6027\u5e38\u91cf\u5bb9\u5668\u201d\uff1bJDK 27 \u5219\u8fdb\u4e00\u6b65\u63d0\u7eaf\uff0c\u53ea\u4fdd\u7559\u6700\u7b26\u5408\u201c\u5e38\u91cf\u201d\u672c\u8d28\u7684\u8bed\u4e49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd<code>\u505a\u51cf\u6cd5\u7684\u8bbe\u8ba1\u54f2\u5b66<\/code>\u5728 Java \u8fd1\u5e74\u7684\u65b0\u7279\u6027\u4e2d\u8d8a\u6765\u8d8a\u5e38\u89c1\u3002Project Amber \u7684\u6a21\u5f0f\u5339\u914d\u3001Project Loom \u7684\u7ed3\u6784\u5316\u5e76\u53d1\uff0c\u90fd\u662f\u5728\u53cd\u590d\u9884\u89c8\u4e2d\u4e0d\u65ad\u780d\u6389\u201c\u770b\u8d77\u6765\u6709\u7528\u4f46\u4f1a\u5f15\u5165\u590d\u6742\u6027\u201d\u7684\u8fb9\u7f18\u529f\u80fd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u9700\u8981 ofLazy() \u5de5\u5382\u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u80fd\u6709\u8bfb\u8005\u4f1a\u95ee\uff1a\u65e2\u7136\u5df2\u7ecf\u6709\u4e86 <code>LazyConstant.of()<\/code>\uff0c\u4e3a\u4ec0\u4e48\u8fd8\u8981\u5728 <code>List<\/code>\u3001<code>Set<\/code>\u3001<code>Map<\/code> \u63a5\u53e3\u4e0a\u65b0\u589e <code>ofLazy()<\/code>\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b54\u6848\u662f<code>\u7ec4\u5408\u6027\u4e0e\u6027\u80fd<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8003\u8651\u4e00\u4e2a\u5bf9\u8c61\u6c60\u7684\u573a\u666f\u3002\u7528 <code>LazyConstant<\/code> \u5355\u4e2a\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7b28\u62d9\uff1a\u9700\u8981\u624b\u52a8\u7ba1\u7406\u6570\u7ec4\u548c\u7d22\u5f15\nstatic final LazyConstant&lt;OrderController&gt;[] ORDERS = ...;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c\u7528 <code>List.ofLazy()<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static final List&lt;OrderController&gt; ORDERS =\n    List.ofLazy(POOL_SIZE, _ -&gt; new OrderController());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u8005\u4e0d\u4ec5\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u66f4\u91cd\u8981\u7684\u662f\uff1a<code>JVM \u53ef\u4ee5\u5bf9\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u60f0\u6027\u5143\u7d20\u72ec\u7acb\u8fdb\u884c\u5e38\u91cf\u6298\u53e0<\/code>\u3002<code>List.ofLazy()<\/code> \u8fd4\u56de\u7684\u5217\u8868\u4e2d\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b58\u50a8\u5728 <code>@Stable<\/code> \u6ce8\u89e3\u7684\u5b57\u6bb5\u4e2d\uff0cJVM \u4fe1\u4efb\u8fd9\u4e9b\u503c\u521d\u59cb\u5316\u540e\u4e0d\u518d\u53d8\u5316\uff0c\u4ece\u800c\u53ef\u4ee5\u8fdb\u884c\u6fc0\u8fdb\u7684\u5185\u8054\u548c\u7f13\u5b58\u4f18\u5316\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Set.ofLazy()<\/code> \u7684\u52a0\u5165\u5219\u8865\u5168\u4e86\u6700\u540e\u4e00\u4e2a\u62fc\u56fe\u3002\u5f53\u6211\u4eec\u9700\u8981\u201c\u4e00\u7ec4\u9884\u5b9a\u4e49\u5019\u9009\u503c\u7684\u60f0\u6027\u5224\u5b9a\u201d\u65f6\uff0c\u4e0d\u518d\u9700\u8981\u624b\u52a8\u7528 <code>Map.ofLazy()<\/code> \u6a21\u62df\u96c6\u5408\u8bed\u4e49\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9\u5f00\u53d1\u8005\u7684\u5b9e\u9645\u610f\u4e49<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u529f\u80fd\u53ef\u80fd\u8fd8\u4e0d\u662f\u6700\u540e\u4e00\u6b21\u9884\u89c8\uff0c\u6309\u7167\u5b98\u65b9\u73b0\u5728\u7684\u5c3f\u6027\uff0c\u6211\u4f30\u8ba1\u8bf4\u4e0d\u5b9a\u5230 JDK 29 \u624d\u80fd\u771f\u6b63\u7684\u201c\u843d\u5730\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136\uff0c\u4f46\u662f\uff0c\u8fd9\u4e2a\u529f\u80fd\u5bf9\u6211\u4eec\u5374\u6709\u8fd9\u975e\u5e38\u591a\u7684\u5b9e\u9645\u610f\u4e49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u542f\u52a8\u6027\u80fd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f0\u6027\u5e38\u91cf\u6700\u76f4\u63a5\u7684\u597d\u5904\u662f\u201c\u6539\u5584\u5e94\u7528\u542f\u52a8\u65f6\u95f4\u201d\u3002\u5927\u578b\u5e94\u7528\u4e2d\uff0c\u7ec4\u4ef6\u7684\u521d\u59cb\u5316\u5f80\u5f80\u6784\u6210\u542f\u52a8\u74f6\u9888\u3002\u7528 <code>LazyConstant<\/code> \u91cd\u6784\u540e\uff0c\u7ec4\u4ef6\u53ea\u5728\u771f\u6b63\u88ab\u4f7f\u7528\u65f6\u624d\u521d\u59cb\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Application {\n    static final LazyConstant&lt;OrderController&gt; ORDERS = LazyConstant.of(OrderController::new);\n    static final LazyConstant&lt;UserService&gt; USERS = LazyConstant.of(UserService::new);\n\n    public static OrderController orders() { return ORDERS.get(); }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ebf\u7a0b\u5b89\u5168<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LazyConstant<\/code> \u5185\u90e8\u901a\u8fc7 <code>@Stable<\/code> \u6ce8\u89e3\u548c\u5185\u5b58\u5c4f\u969c\u4fdd\u8bc1<code>\u521d\u59cb\u5316\u81f3\u591a\u53d1\u751f\u4e00\u6b21<\/code>\uff0c\u4e14\u65e0\u9700\u663e\u5f0f\u540c\u6b65\u3002\u8fd9\u6bd4\u624b\u5199\u53cc\u91cd\u68c0\u67e5\u9501\u5b9a\uff08DCL\uff09\u6216 <code>volatile<\/code> \u5b57\u6bb5\u66f4\u5b89\u5168\u3001\u66f4\u9ad8\u6548\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JVM \u4f18\u5316<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u8981\u5c06 <code>LazyConstant<\/code> \u5b58\u50a8\u5728 <code>final<\/code> \u5b57\u6bb5\u4e2d\uff0cJVM \u5c31\u80fd\u5bf9\u5176\u5185\u5bb9\u8fdb\u884c<code>\u5e38\u91cf\u6298\u53e0<\/code>\u3002\u8fd9\u610f\u5473\u7740\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Application.orders().getLogger().info(\"...\");<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c <code>orders()<\/code> \u548c <code>getLogger()<\/code> \u90fd\u8fd4\u56de\u5b58\u50a8\u5728 <code>final<\/code> \u5b57\u6bb5\u4e2d\u7684\u60f0\u6027\u5e38\u91cf\uff0cJVM \u53ef\u80fd\u5728\u7f16\u8bd1\u65f6\u76f4\u63a5\u5185\u8054\u6700\u7ec8\u7684 <code>Logger<\/code> \u5b9e\u4f8b\uff0c\u6d88\u9664\u65b9\u6cd5\u8c03\u7528\u5f00\u9500\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3\u4e0e\u5c55\u671b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JEP 531 \u7684\u7b2c\u4e09\u6b21\u9884\u89c8\u663e\u793a\uff0c<code>\u60f0\u6027\u5e38\u91cf\u7279\u6027\u6b63\u5728\u8d70\u5411\u6210\u719f<\/code>\u3002\u7ecf\u8fc7\u4e09\u6b21\u8fed\u4ee3\uff0cAPI \u8868\u9762\u5df2\u7ecf\u76f8\u5f53\u7cbe\u7b80\u4e86\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6838\u5fc3\u63a5\u53e3 <code>LazyConstant<\/code> \u53ea\u5269\u4e0b <code>get()<\/code> \u548c\u5de5\u5382\u65b9\u6cd5<\/li><li>\u4e09\u5927\u96c6\u5408\u7c7b\u578b\u7684 <code>ofLazy()<\/code> \u5de5\u5382\u65b9\u6cd5\u8865\u9f50<\/li><li>\u7981\u6b62 <code>null<\/code>\uff0c\u907f\u514d\u8bed\u4e49\u6a21\u7cca<\/li><li>\u79fb\u9664\u6240\u6709\u53ef\u80fd\u7834\u574f&#8221;\u900f\u660e\u60f0\u6027&#8221;\u7684\u65b9\u6cd5<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6309\u7167 OpenJDK \u7684\u60ef\u4f8b\uff0c\u4e00\u4e2a\u9884\u89c8\u7279\u6027\u901a\u5e38\u7ecf\u5386 2-4 \u8f6e\u9884\u89c8\u540e\u5c31\u4f1a\u6700\u7ec8\u786e\u5b9a\u3002JEP 531 \u5df2\u7ecf\u662f\u7b2c\u4e09\u8f6e\uff0c\u4e14\u672c\u8f6e\u6539\u52a8\u5e45\u5ea6\u660e\u663e\u5c0f\u4e8e\u4e0a\u4e00\u8f6e\uff08JDK 26 \u7684\u91cd\u6784\u5e45\u5ea6\u8fdc\u5927\u4e8e JDK 27 \u7684\u7cbe\u4fee\uff09\u3002\u6211\u4eec\u5f88\u53ef\u80fd\u6700\u65e9\u5728 JDK 28 \u770b\u5230\u5b83\u6210\u4e3a\u6b63\u5f0f\u7279\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e Java \u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u4e45\u540e\u6211\u4eec\u5c31\u80fd\u7528\u4e00\u79cd<code>\u58f0\u660e\u5f0f\u3001\u7ebf\u7a0b\u5b89\u5168\u3001JVM \u53ef\u4f18\u5316<\/code>\u7684\u65b9\u5f0f\u6765\u66ff\u4ee3\u624b\u5199\u7684 DCL \u548c <code>volatile<\/code> \u61d2\u52a0\u8f7d\u6a21\u5f0f\uff0c\u800c\u4e14\u4ee3\u7801\u4f1a\u66f4\u7b80\u6d01\u3001\u66f4\u53ef\u9760\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u671f\u5f85\u66f4\u591a\u7684 JEP \u7a33\u5b9a\u843d\u5730\uff0c\u8ba9 Java \u518d\u6b21\u4f1f\u5927\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=5712\">JDK 27 \u53c8\u628a API \u780d\u4e86\u4fe9\u65b9\u6cd5\uff0cJEP 531 \u548c Set.ofLazy() \u6765\u4e86<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5927\u7ea6 1 \u4e2a\u6708\u4e4b\u524d\uff0c\u6211\u5199\u4e86\u4e00\u7bc7\u5173\u4e8e JDK 27 \u7684\u6587\u7ae0\uff0c\u5f53\u65f6\u7684 JDK 27 \u8fd8\u53ea\u6709\u4e00\u4e2a JEP\u3002\u73b0\u5728\uff0c\u968f\u7740 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1334,1515,2094,1538,810],"class_list":["post-5712","post","type-post","status-publish","format-standard","hentry","category-java","tag-jdk8","tag-jetty","tag-openjdk","tag-openmessaging","tag-openurl"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5712"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5712\/revisions"}],"predecessor-version":[{"id":5713,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5712\/revisions\/5713"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}