{"id":512287,"date":"2021-06-13T05:23:09","date_gmt":"2021-06-12T21:23:09","guid":{"rendered":"http:\/\/4563.org\/?p=512287"},"modified":"2021-06-13T05:23:09","modified_gmt":"2021-06-12T21:23:09","slug":"%e6%9d%a5%e4%ba%86%e6%9d%a5%e4%ba%86%ef%bc%8c%e5%ae%8c%e6%95%b4%e6%94%af%e6%8c%81-java-%e5%86%85%e6%8f%92%e5%ad%97%e7%ac%a6%e4%b8%b2-%e8%af%ad%e6%b3%95%e7%9a%84%e6%8f%92%e4%bb%b6%e6%9d%a5%e4%ba%86","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=512287","title":{"rendered":"\u6765\u4e86\u6765\u4e86\uff0c\u5b8c\u6574\u652f\u6301 [ Java \u5185\u63d2\u5b57\u7b26\u4e32] \u8bed\u6cd5\u7684\u63d2\u4ef6\u6765\u4e86"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u6765\u4e86\u6765\u4e86\uff0c\u5b8c\u6574\u652f\u6301 [ Java \u5185\u63d2\u5b57\u7b26\u4e32] \u8bed\u6cd5\u7684\u63d2\u4ef6\u6765\u4e86 <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 122006 <\/span>  <span><i><\/i> 9<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>2.0+\u7248\u672c\u5b8c\u6574\u652f\u6301\u5185\u63d2\u5b57\u7b26\u4e32\uff0c\u62e5\u6709\u4ee3\u7801\u6bb5 idea \u63d0\u793a\u3001\u524d\u7f00\u6807\u8bc6\u3001\u9ad8\u7ea7\u8bed\u6cd5\u7cd6\u7b49\u7279\u6027\uff0c\u6b22\u8fce\u5927\u5bb6\u6307\u6559<\/h2>\n<h1>\u9879\u76ee\u5730\u5740122006\/Zircon<\/h1>\n<p> <\/p>\n<p>(:\u6b22\u8fce star<\/p>\n<h3>\u4ec0\u4e48\u53eb\u5185\u63d2\u5b57\u7b26\u4e32\uff1f<\/h3>\n<p>\u5b57\u7b26\u4e32\u63d2\u503c\u529f\u80fd\u6784\u5efa\u5728\u590d\u5408\u683c\u5f0f\u8bbe\u7f6e\u529f\u80fd\u7684\u57fa\u7840\u4e4b\u4e0a\uff0c\u63d0\u4f9b\u66f4\u5177\u6709\u53ef\u8bfb\u6027\u3001\u66f4\u65b9\u4fbf\u7684\u8bed\u6cd5\uff0c\u7528\u4e8e\u5c06\u8868\u8fbe\u5f0f\u7ed3\u679c\u5305\u62ec\u5230\u7ed3\u679c\u5b57\u7b26\u4e32\u3002<\/p>\n<h3>\u5982\u4f55\u4f7f\u7528\u5185\u63d2\u5b57\u7b26\u4e32<\/h3>\n<p>\u82e5\u8981\u5c06\u5b57\u7b26\u4e32\u6807\u8bc6\u4e3a\u5185\u63d2\u5b57\u7b26\u4e32\uff0c\u53ef\u5728\u8be5\u5b57\u7b26\u4e32\u524d\u9762\u52a0\u4e0a <code>$<\/code>\u6216<code>f<\/code> \u7b26\u53f7\u3002 \u53ef\u5d4c\u5165\u4efb\u4f55\u4f1a\u5728\u5185\u63d2\u5b57\u7b26\u4e32\u4e2d\u8fd4\u56de\u503c\u7684\u6709\u6548 JAVA \u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u5bf9\u67d0\u4e2a\u8868\u8fbe\u5f0f\u6267\u884c\u8ba1\u7b97\u540e\uff0c\u5176\u7ed3\u679c\u7acb\u5373\u8f6c\u6362\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u5305\u542b\u5230\u7ed3\u679c\u5b57\u7b26\u4e32\u4e2d\uff1a<\/p>\n<h3>\u7279\u6027<\/h3>\n<ol>\n<li>\n<p>\u652f\u6301 android \u3001java \u7b49\u6240\u6709\u4f7f\u7528 javac \u7684\u9879\u76ee<\/p>\n<\/li>\n<li>\n<p>\u51e0\u4e4e\u4e0d\u4f1a\u589e\u52a0\u989d\u5916\u7f16\u8bd1\u65f6\u95f4<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u5185\u5bb9\u652f\u6301 idea \u8865\u5168\u63d0\u793a\uff08\u9700\u5b89\u88c5 idea \u63d2\u4ef6\uff09 <\/p>\n<\/li>\n<li>\n<p>\u66f4\u591a\u5185\u63d2\u5b57\u7b26\u4e32\u8bed\u6cd5\u7cd6\u652f\u6301<\/p>\n<\/li>\n<\/ol>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<p><code>String text=f\" this is F-$String.class.getSimpleName() \";<\/code><\/p>\n<p><code>assert Objects.equals($\"Zircon: [ ${text.trim()} ]\",\"Zircon: [ \"+text.trim()+\" ]\");<\/code><\/p>\n<h3>\u9ad8\u7ea7\u8bed\u6cd5\u7cd6<\/h3>\n<ol>\n<li>\n<p>\u6839\u636e\u5b57\u7b26\u4e32\u524d\u7684\u524d\u7f00\u4e0d\u540c\uff0c\u62e5\u6709\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\u5185\u63d2\u903b\u8f91\uff0c\u8bf7\u6ce8\u610f\u533a\u522b\u4f7f\u7528<\/p>\n<h4>1. <code>$<\/code>\u524d\u7f00\u5b57\u7b26\u4e32(<code>$-string<\/code>):<\/h4>\n<p>\u76f4\u63a5\u4f7f\u7528\u52a0\u53f7\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u62fc\u63a5\uff0c\u62e5\u6709\u6700\u5feb\u7684\u8fd0\u884c<\/p>\n<ol>\n<li>\n<p>JDK1.6 \u7684\u60c5\u51b5\uff0cjavac \u9047\u5230\u52a0\u53f7(<code>+<\/code>)\u94fe\u63a5\u7684\u5b57\u7b26\u4e32\u4f1a\u81ea\u52a8\u8f6c\u5316\u6210<code>StringBuilder.append()<\/code>\uff0c\u4e0d\u5b58\u5728\u52a0\u53f7\u8fde\u63a5\u5b57\u7b26\u4e32\u989d\u5916\u7684\u5bf9\u8c61\u5f00\u9500<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u9996\u4e2a\u5b50\u90e8\u5206\u4e3a\u975e\u786c\u7f16\u7801\u5b57\u7b26\u4e32\uff0c\u4f1a\u81ea\u52a8\u5305\u88f9<code>String.valueOf()<\/code>\u4ee5\u9632\u6b62\u62fc\u63a5\u5f02\u5e38<\/p>\n<\/li>\n<\/ol>\n<h4>2. <code>f<\/code>\u524d\u7f00\u5b57\u7b26\u4e32(<code>f-string<\/code>):<\/h4>\n<p>\u4f7f\u7528 String.format \u51fd\u6570\u8fdb\u884c\u62fc\u63a5\uff0c\u901f\u5ea6\u76f8\u6bd4<code>$-string<\/code>\u8f83\u6162<\/p>\n<ol>\n<li>\u5982\u679c\u662f\u4f7f\u7528\u5927\u62ec\u53f7\u5305\u88f9\u7684<code>${}<\/code>\u4ee3\u7801\u5757\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u7684\u6bcf\u4e2a\u5185\u63d2\u4ee3\u7801\u5757\u7684\u663e\u793a\u683c\u5f0f\uff1a \u5728\u4ee3\u7801\u5757\u7684\u524d\u90e8\uff0c\u589e\u52a0\u4e00\u4e2a\u4ee5<code>%<\/code>\u53f7\u5f00\u59cb\u7684<code>String.format<\/code>\u683c\u5f0f\u5316\u6807\u8bc6\uff0c\u5e76\u4e14\u4f7f\u7528<code>:<\/code>\u4e0e\u540e\u7eed\u4ee3\u7801\u5757\u8fdb\u884c\u5206\u9694 \u3002\u5f62\u5982\uff1a<code>${%03d:12}<\/code>\u4f1a\u8f93\u51fa<code>012<\/code>\u7684\u683c\u5f0f\u5316\u7ed3\u679c<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u672a\u88ab\u5927\u62ec\u53f7<code>{}<\/code>\u5305\u88f9\u7684\u7b80\u6613\u4ee3\u7801\u5757\uff0c\u62e5\u6709 java \u7279\u6027\u81ea\u52a8\u8bc6\u522b\u4ee3\u7801\u8303\u56f4\u7684\u529f\u80fd<\/p>\n<ol>\n<li>\n<p>\u8bf7\u4e0d\u8981\u5b8c\u5168\u4f9d\u8d56\u8be5\u529f\u80fd\uff0c\u53ea\u80fd\u7b80\u5355\u5224\u65ad\u62ec\u53f7\u5339\u914d\u53ca\u540e\u7eed\u5f15\u7528\uff0c\u590d\u6742\u8bed\u53e5\u8bf7\u4f7f\u7528<code>${}<\/code><\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u8981\u4f7f\u7528\u8be5\u529f\u80fd\uff0c\u8bf7\u6ce8\u610f\u6839\u636e\u63d2\u4ef6\u63d0\u793a\u7684 java \u4ee3\u7801\u6ce8\u5165\u8303\u56f4\u6765\u5224\u65ad\u662f\u5426\u4f7f\u7528\u9519\u8bef<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u4e3a\u51cf\u5c11\u8f6c\u4e49\u53cc\u5f15\u53f7\u7684\u60c5\u51b5\uff0c<code>${}<\/code>\u5185\u53ef\u4ee5\u4f7f\u7528\u5355\u5f15\u53f7\u4ee5\u66ff\u4ee3\u53cc\u5f15\u53f7<\/p>\n<ol>\n<li>\u5982\u679c\u9700\u8981\u4f7f\u7528\u5355\u5f15\u53f7\u4ee5\u58f0\u660e<code>char<\/code>\u7c7b\u578b\uff0c\u4f60\u9700\u8981\u4f7f\u7528<code>'C'<\/code>\u8fdb\u884c\u8f6c\u4e49<\/li>\n<\/ol>\n<\/li>\n<\/ol><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"6039662\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 122006 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u5927\u5bb6\u4e00\u822c\u662f\u600e\u4e48\u62fc\u63a5\u5b57\u7b26\u4e32\u7684\u5462 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"6039663\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cweijan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u4e0d\u662f\u5f88\u770b\u597d, \u9664\u975e\u80fd\u50cf lombok \u4e00\u6837\u88ab idea \u5b98\u65b9\u96c6\u6210. <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"6039664\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 122006 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @cweijan \u7eaf\u81ea\u7528\uff0c\u4e5f\u6ca1\u5565\u63a8\u5e7f\u7684\u91ce\u5fc3\uff0c\u81ea\u5df1\u5199\u7684\u8212\u670d\u70ab\u4e0b\u6280\u672f\u597d\u4e86<br \/>\u9762\u8bd5\u7684\u65f6\u5019\u62ff\u6765\u5439\u4e2a\u725b\u4e0d\u9999\u4e48 <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u4e86\u6765\u4e86\uff0c\u5b8c\u6574\u652f\u6301 [ Java &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/512287"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=512287"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/512287\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=512287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=512287"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=512287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}