{"id":8764,"date":"2024-05-27T14:01:01","date_gmt":"2024-05-27T06:01:01","guid":{"rendered":""},"modified":"2024-05-27T14:01:01","modified_gmt":"2024-05-27T06:01:01","slug":"pmml java_\u521d\u5b66\u8005\u600e\u6837\u770b\u61c2\u4ee3\u7801","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8764.html","title":{"rendered":"pmml java_\u521d\u5b66\u8005\u600e\u6837\u770b\u61c2\u4ee3\u7801"},"content":{"rendered":"
\u672c\u6587\u7ed3\u5408\u5b9e\u4f8b\uff0c\u8bb2\u8bc9\u5982\u4f55\u5199\u51fa\u7b26\u5408PMD\u7f16\u7a0b\u89c4\u8303\u7684java\u4ee3\u7801\u3002<\/p>\n
\u9605\u8bfb\u524d\u9700\u8981\u6709\u4e00\u4e2a\u5171\u8bc6\uff1a\u4f18\u96c5\u7684\u4ee3\u7801\u4e00\u5b9a\u662f\u6700\u8ba9\u4eba\u559c\u6b22\u7684\u3002<\/span><\/p>\n \u4e0b\u9762\u9644\u4e0a\u4ee3\u7801\u89c4\u8303\u7684pmd.xml\u6587\u4ef6\u7684\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/github.com\/jitongming\/pmdForDev<\/p>\n \u76ee\u5f55<\/strong><\/p>\n \u7b2c\u4e00\u7c7b\uff1abasic<\/p>\n \u7b2c\u4e8c\u7c7b\uff1aunnecessary<\/p>\n \u7b2c\u4e09\u7c7b\uff1abraces<\/p>\n \u7b2c\u56db\u7c7b\uff1acodesize<\/p>\n \u7b2c\u4e94\u7c7b\uff1acontroversial<\/p>\n \u7b2c\u516d\u7c7b\uff1acoupling<\/p>\n \u7b2c\u4e03\u7c7b\uff1adesign<\/p>\n \u7b2c\u516b\u7c7b\uff1aempty<\/p>\n \u7b2c\u4e5d\u7c7b\uff1afinalizers<\/p>\n \u7b2c\u5341\u7c7b\uff1aimports<\/p>\n \u7b2c\u5341\u4e00\u7c7b\uff1aj2ee<\/p>\n \u7b2c\u5341\u4e8c\u7c7b\uff1alogging-java<\/p>\n \u7b2c\u5341\u4e09\u7c7b\uff1anaming<\/p>\n \u7b2c\u5341\u56db\u7c7b\uff1aoptimizations<\/p>\n \u7b2c\u5341\u4e94\u7c7b\uff1astrictexception<\/p>\n \u7b2c\u5341\u516d\u7c7b\uff1astrings<\/p>\n \u7b2c\u5341\u4e03\u7c7b\uff1aunusedcode<\/p>\n ------------------------------\u6211\u662f\u53ef\u7231\u7684\u5206\u5272\u7ebf-----------------------------------<\/p>\n 1\uff09ReturnFromFinallyBlock\u3010\u4e0d\u8981\u5728finally\u4ee3\u7801\u5757\u4e2d\u4f7f\u7528return\u3011<\/strong><\/p>\n 2\uff09UnconditionalIfStatement\u3010if\u8bed\u53e5\u5224\u65ad\u6761\u4ef6\uff0c\u4e0d\u80fd\u6c38\u8fdc\u6210\u7acb\uff0c\u5fc5\u5b9a\u662ftrue\u6216false\u3011<\/strong><\/p>\n <\/p>\n 1\uff09UnnecessaryConversionTemporary\u3010\u4e0d\u8981\u6d6a\u8d39\u4e00\u4e2aobject\u8fdb\u884c\u57fa\u7840\u6570\u503c\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\uff0c\u4f7f\u7528\u5305\u88c5\u7c7b\u76f4\u63a5\u5904\u7406\u3011<\/strong><\/p>\n <\/p>\n 2\uff09UnnecessaryFinalModifier\u3010\u5220\u9664\u4e0d\u5fc5\u8981\u7684final\u4fee\u9970\u7b26\u3011<\/strong><\/p>\n 1\uff09ForLoopsMustUseBraces\u3010for\u5faa\u73af\u5fc5\u987b\u7528{}\u5305\u542b\u8d77\u6765\u3011<\/strong><\/p>\n 2\uff09IfElseStmtsMustUseBraces\u3010if..else..\u8bed\u53e5\u5fc5\u987b\u7528{}\u5305\u542b\u8d77\u6765\u3011<\/strong><\/p>\n
\n
\n\u7b2c\u4e00\u7c7b\uff1abasic<\/h2>\n
\n
public void test(){\n try{\n \/\/......do something \n }catch(Exception e){\n \/\/......do something\n }finally{\n return \"\u5728\u8fd9\u8fdb\u884c\u8fd4\u56de\"; \/\/\u907f\u514d\u5728\u8fd9\u91cc\u5199return\n }\n}<\/code><\/pre>\n
\n
public void test(){\n if(0<1){ \/\/\u907f\u514d\u4ee5\u7edd\u5bf9\u6210\u7acb\u7684\u6761\u4ef6\u4f5c\u4e3a\u5224\u65ad\u4f9d\u636e\n \/\/....do something\n }\n}<\/code><\/pre>\n
\u7b2c\u4e8c\u7c7b\uff1aunnecessary<\/h2>\n
\n
String a = new Integer(x).toString();\/\/1.\u907f\u514d\u5199\u6cd5\uff1a\u6d6a\u8d39\u4e86\u4e00\u4e2aobject\n\nString a= Integer.toString(x);\/\/2.\u63a8\u8350\u5199\u6cd5<\/code><\/pre>\n
\n
public final class Test{\n\n public final String method1(){\/\/1.\u907f\u514d\u5199\u6cd5\n return \"test\";\n }\n\n public String method2(){\/\/\u63a8\u8350\u5199\u6cd5\n return \"test\";\n }\n}<\/code><\/pre>\n
\u7b2c\u4e09\u7c7b\uff1abraces<\/h2>\n
\n
int a=0;\nfor(int i=0;i<100;i++) \/\/1.\u907f\u514d\u5199\u6cd5\n a+=i;\n\nfor(int i=0;i<100;i++) {\/\/2.\u63a8\u8350\u5199\u6cd5\n a+=i;\n}\n<\/code><\/pre>\n
\n
int a=1;\nint b=2;\n\nif(1==a) \/\/1.\u907f\u514d\u5199\u6cd5\n b=a; \nelse\n b+=a;\n\n\nif(1==a){\/\/2.\u63a8\u8350\u5199\u6cd5\n b=a; \n}else{\n b+=a;\n}<\/code><<\/pre>\n","protected":false},"excerpt":{"rendered":"pmml java_\u521d\u5b66\u8005\u600e\u6837\u770b\u61c2\u4ee3\u7801\u672c\u6587\u7ed3\u5408\u5b9e\u4f8b\uff0c\u8bb2\u8bc9\u5982\u4f55\u5199\u51fa\u7b26\u5408PMD\u7f16\u7a0b\u89c4\u8303\u7684java\u4ee3\u7801","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8764"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8764"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8764\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}