{"id":77374,"date":"2020-09-23T01:24:46","date_gmt":"2020-09-23T01:24:46","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=idea&#038;p=77374"},"modified":"2020-09-23T12:40:50","modified_gmt":"2020-09-23T12:40:50","slug":"intellij-idea","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/zh-hans\/idea\/2020\/09\/intellij-idea\/","title":{"rendered":"IntelliJ IDEA \u4e2d\u7684\u65e5\u5e38\u91cd\u6784\u6280\u5de7"},"content":{"rendered":"<p>\u6211\u4eec\u7ecf\u5e38\u4f1a\u51fa\u4e8e\u5f88\u591a\u539f\u56e0\u66f4\u6539\u5de5\u4f5c\u4ee3\u7801\uff0c\u6bd4\u5982\u4fee\u590d\u9519\u8bef\u3001\u63d0\u9ad8\u53ef\u8bfb\u6027\u3001\u589e\u52a0\u65b0\u529f\u80fd\u7b49\u3002 \u672c\u7bc7\u535a\u5ba2\u8bb2\u8ff0\u65e5\u5e38\u91cd\u6784\u3002<\/p>\n<p><iframe loading=\"lazy\" frameborder=\"0\" width=\"640\" height=\"498\" src=\"https:\/\/v.qq.com\/txp\/iframe\/player.html?vid=p3155806ck7\" style=\"width:100%;border:none;\" allowfullscreen><\/iframe><\/p>\n<p>\u672c\u7bc7\u535a\u6587\u4e0e\u89c6\u9891\u6db5\u76d6\u76f8\u540c\u7684\u6750\u6599\u3002 \u5bf9\u4e8e\u559c\u6b22\u9605\u8bfb\u6587\u7ae0\u800c\u4e0d\u559c\u6b22\u89c2\u770b\u89c6\u9891\u7684\u8bfb\u8005\uff0c\u53ef\u4ee5\u901a\u8fc7\u672c\u6587\u5feb\u901f\u6d4f\u89c8\u5185\u5bb9\u3002\u8bfb\u8005\/\u89c2\u770b\u8005\u90fd\u53ef\u4ee5\u83b7\u5f97\u4ee3\u7801\u793a\u4f8b\u548c\u6307\u5411\u5176\u4ed6\u4fe1\u606f\u7684\u94fe\u63a5\u3002<br \/>\n\u53ef\u4ee5\u5728<a href=\"https:\/\/github.com\/malagupta\/RefactoringDemo\" target=\"_blank\" rel=\"noopener\">\u6b64\u5904<\/a>\u83b7\u5f97\u672c\u7bc7\u535a\u6587\u6240\u7528\u7684\u4ee3\u7801\u3002<\/p>\n<h2>\u91cd\u547d\u540d\u5143\u7d20<\/h2>\n<p>\u76f4\u63a5\u5728\u7c7b\u6587\u4ef6\u4e2d\u624b\u52a8\u91cd\u547d\u540d\u5e76\u4e0d\u5b89\u5168\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5728\u7f16\u8f91\u5668\u4e2d\u5c06 <a href=\"https:\/\/github.com\/malagupta\/RefactoringDemo\/blob\/master\/out\/production\/RefactoringDemo\/com\/jetbrains\/Bug.class\" target=\"_blank\" rel=\"noopener\">Bug \u7c7b<\/a>\u91cd\u547d\u540d\u4e3a ABug\uff0c\u53ef\u80fd\u4f1a\u9519\u8fc7\u66f4\u65b0\u4f7f\u7528\u5b83\u7684\u6240\u6709\u5176\u4ed6\u4ee3\u7801\u3002 \u4ece <a href=\"https:\/\/blog.jetbrains.com\/idea\/2020\/06\/intellij-idea-2020-2-eap-5-java-15-related-problems-intentions-preview-and-more\/\">IntelliJ IDEA 2020.2 \u5f00\u59cb\uff0c\u60a8\u4f1a\u5728\u7f16\u8f91\u5668\u4e2d\u770b\u5230\u201c\u76f8\u5173\u95ee\u9898\u201d<\/a>\u7684\u9519\u8bef\u6d88\u606f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/rename_abug.png\" alt=\"Rename the Bug class to ABug\" \/><br \/>\n<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/rename-refactorings.html#inplace_rename\" target=\"_blank\" rel=\"noopener\">\u5c31\u5730\u91cd\u547d\u540d\u91cd\u6784<\/a>\u5728\u95f4\u8ddd\u4e2d\u9ad8\u4eae\u663e\u793a\u3002 \u70b9\u51fb\u95f4\u8ddd\u4e2d\u7684 R \u56fe\u6807\uff0c\u6211\u4eec\u53ef\u4ee5<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/refactoring-source-code.html#refactoring_preview\" target=\"_blank\" rel=\"noopener\">\u9884\u89c8<\/a>  Bug \u5230 ABug \u6240\u6709\u7528\u6cd5\u7684\u91cd\u547d\u540d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/rename_with_preview.png\" alt=\"Rename class with preview\" \/><\/p>\n<p>IntelliJ IDEA  \u8fd8\u53ef\u4ee5\u67e5\u627e\u540d\u79f0\u76f8\u4f3c\u7684\u53d8\u91cf\uff0c\u8ba9\u6211\u4eec\u9009\u62e9\u8981\u66f4\u65b0\u7684\u53d8\u91cf\u3002<br \/>\n\u53e6\u5916\uff0c\u5728\u7f16\u8f91\u5668\u4e2d\u66f4\u6539\u7c7b\u540d\u79f0\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5feb\u6377\u952e \u2325\u23ce \u6216 <strong>Alt+Enter<\/strong> \u91cd\u590d\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528 \u21e7F6\uff0c\u6216\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 Shift+F6 \u6765\u8c03\u7528\u91cd\u547d\u540d\u91cd\u6784\uff0cIntelliJ IDEA \u5c06\u4e3a\u60a8\u7684\u7c7b\u3001\u65b9\u6cd5\u548c\u53d8\u91cf<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/rename-refactorings.html\" target=\"_blank\" rel=\"noopener\">\u5efa\u8bae\u66ff\u4ee3\u540d\u79f0<\/a>\u3002 \u5982\u679c\u9009\u62e9\u65b0\u7684\u540d\u79f0\uff0cIntelliJ IDEA \u4f1a\u5b89\u5168\u5730\u5b8c\u6210\u91cd\u6784\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class Bug {\n    private long id;\n    private String description;\n\n    public Bug(long id, String description) {\n        this.id = id;\n        this.description = description;\n    }\n\n    public long getId() {\n        return id;\n    }\n\n    public String getDescription() {\n        return description;\n    }\n}<\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5c06\u5b57\u6bb5 <code>description<\/code> \u91cd\u547d\u540d\u4e3a <code>desc<\/code>\uff0cIntelliJ IDEA \u4f1a\u68c0\u6d4b\u6b64\u5b57\u6bb5\u662f\u5426\u7528\u4e8e <code>getter<\/code> \u548c <code>setter<\/code> \u65b9\u6cd5\uff0c\u5e76\u8be2\u95ee\u6211\u4eec\u662f\u5426\u66f4\u65b0\u3002 \u5b83\u8fd8\u4f1a\u66f4\u65b0\u8be5\u5b57\u6bb5\u5728\u65b9\u6cd5\u53c2\u6570\u540d\u79f0\u4e2d\u7684\u7528\u6cd5\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/rename_variable.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/rename_variable.gif\" ><\/p>\n<p>\u8ba9\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u540d\u4e3a <code>View<\/code> \u7684\u63a5\u53e3\uff0c\u5b83\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b9\u6cd5 <code>getItems<\/code>\u3002 \u6211\u4eec\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2318B<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+B<\/strong> \u6765<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/find-highlight-usages.html\" target=\"_blank\" rel=\"noopener\">\u5bfc\u822a\u5230\u5b83\u7684\u7528\u6cd5<\/a>\u3002 \u6b64\u63a5\u53e3\u7531\u7c7b <code>ViewImpl<\/code> \u5b9e\u73b0\u3002<\/p>\n<p>\u5728\u540d\u4e3a <code>View<\/code> \u7684\u63a5\u53e3\u4e2d\uff0c\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u21e7F6<\/strong> \u6216\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Shift+F6<\/strong>\uff0c\u5c06\u65b9\u6cd5 <code>getItems<\/code> \u91cd\u547d\u540d\u4e3a <code>getItemsList<\/code>\u3002 \u5f53\u6211\u4eec\u6309 Enter \u65f6\uff0c\u5b83\u7684\u5b9e\u73b0\u4f1a\u5728 <code>ViewImpl<\/code> \u7c7b\u4e2d\u66f4\u65b0\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/rename_interface.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/rename_interface.gif\" ><\/p>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u8bbf\u95ee\u9879\u76ee\u7a97\u53e3\uff0c\u5e76\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u21e7F6<\/strong> \u6216\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Shift+F6<\/strong> \u5728\u6587\u4ef6\u540d\u4e0a<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/rename-refactorings.html\" target=\"_blank\" rel=\"noopener\">\u66f4\u6539<\/a>\u7c7b\u3001\u5305\u3001\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u540d\u79f0\u3002<\/p>\n<h2>\u66f4\u6539\u7b7e\u540d<\/h2>\n<p>\u6765\u770b\u770b\u5982\u4f55\u5b89\u5168\u5730<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/change-signature.html\" target=\"_blank\" rel=\"noopener\">\u66f4\u6539\u7c7b\u6216\u65b9\u6cd5<\/a>\u7684\u7b7e\u540d\u3002 \u6211\u4eec\u5728 <code>BugReport<\/code> \u4e2d\u7684\u65b9\u6cd5 <code>binaryStrings<\/code> \u63a5\u53d7\u4e00\u4e2a String \u53c2\u6570\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public boolean binaryStrings(String b) {\n    Stack&lt;Character&gt; s = new Stack&lt;&gt;();\n    for (char c : b.toCharArray())\n        if (s.empty() || !s.peek().equals(c))\n            s.push(c);\n        else\n            s.pop();\n    return s.empty();\n}<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u65b9\u6cd5 <code>binaryStrings<\/code> \u4e2d\u6dfb\u52a0\u4e00\u4e2a\u53c2\u6570\uff0c\u4f8b\u5982\uff0c\u4e00\u4e2a int \u7c7b\u578b\u7684\u8ba1\u6570\u5668\u3002 \u540c\u6837\uff0c\u8fd9\u4e5f\u662f\u4e00\u79cd\u5c31\u5730\u91cd\u6784\uff0c\u5e76\u5c06\u5728\u95f4\u8ddd\u533a\u57df\u4e2d\u4f7f\u7528 R \u56fe\u6807\u9ad8\u4eae\u663e\u793a\u3002 \u6211\u4eec\u53ef\u4ee5\u70b9\u51fb\u95f4\u8ddd\u4e2d\u7684\u56fe\u6807\uff0c\u66f4\u65b0\u65b9\u6cd5\u7b7e\u540d\uff0c\u5411\u53c2\u6570\u6dfb\u52a0\u9ed8\u8ba4\u503c\uff0c\u4ee5\u4fbf\u8ba9\u65b9\u6cd5\u7684\u4efb\u4f55\u8c03\u7528\u8005\u90fd\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/change_method_signature.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/change_method_signature.gif\" ><\/p>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528<strong>\u2325\u23ce<\/strong> \u6216\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Alt+Enter<\/strong> \u66f4\u65b0\u65b9\u6cd5\u7b7e\u540d\u5e76\u6dfb\u52a0\u9ed8\u8ba4\u53c2\u6570\u503c\u3002<\/p>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2318F6<\/strong> \u6216\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+F6<\/strong> \u8c03\u7528 Change Signature <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/change-signature.html\" target=\"_blank\" rel=\"noopener\">\u5bf9\u8bdd\u6846\u66f4\u6539<\/a>\u6cd5\u7b7e\u540d\u3002 \u8ba9\u6211\u4eec\u6dfb\u52a0\u4e00\u4e2a\u5e03\u5c14\u53c2\u6570 state\uff0c\u9ed8\u8ba4\u503c\u4e3a &quot;true&quot;\u3002 \u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6b64\u5bf9\u8bdd\u6846\u66f4\u6539\u53c2\u6570\u987a\u5e8f\u3002 \u5b83\u8fd8\u53ef\u4ee5\u9009\u62e9\u901a\u8fc7\u91cd\u8f7d\u8fdb\u884c\u59d4\u6258\u3002 \u91cd\u6784\u540e\uff0c\u65b9\u6cd5\u5c06\u88ab\u91cd\u8f7d\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/add_overload_bool.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/add_overload_bool.gif\" ><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class MyMap {\n    int count = 0;\n\n    public int getCount() {\n        return count;\n    }\n\n    public void setCount(int Count) {\n        this.count = count;\n    }\n\n    public static void main(String[] args) {\n        MyMap myMap = new MyMap();\n        System.out.println(myMap.getCount());\n    }\n}<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a <code>MyMap<\/code> \u7c7b\u67e5\u770b\u66f4\u6539\u7c7b\u7b7e\u540d\u5bf9\u5b83\u7684\u5f71\u54cd\u3002 \u6211\u4eec\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2318F6<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+F6<\/strong> \u6765\u4fee\u6539\u7c7b\u7b7e\u540d\u3002 \u6211\u4eec\u5411\u5176\u6dfb\u52a0\u4e24\u4e2a\u901a\u7528\u53c2\u6570\uff1a\u4e00\u4e2a\u540d\u4e3a <code>K<\/code>\uff0c\u9ed8\u8ba4\u503c <code>Integer<\/code>\uff1b\u4e00\u4e2a\u540d\u4e3a <code>V<\/code>\uff0c\u9ed8\u8ba4\u503c <code>String<\/code>\u3002 \u91cd\u6784\u7c7b\u540e\uff0c<code>MyMap<\/code> \u7684\u7528\u6cd5\u5c06\u6539\u53d8\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/change_signature.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/change_signature.gif\" ><\/p>\n<h2>\u63d0\u53d6\u65b9\u6cd5<\/h2>\n<p><a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-method.html\" target=\"_blank\" rel=\"noopener\">Extract Method \u91cd\u6784<\/a>\u53ef\u4ee5\u4f7f\u60a8\u7684\u65b9\u6cd5\u66f4\u77ed\u3001\u66f4\u6613\u8bfb\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public boolean binaryStrings(String b) {\n    Stack&lt;Character&gt; s = new Stack&lt;&gt;();\n    for (char c : b.toCharArray())\n        if (s.empty() || !s.peek().equals(c))\n            s.push(c);\n        else\n            s.pop();\n    return s.empty();\n}<\/pre>\n<p>\u8ba9\u6211\u4eec\u5728 <code>binaryStrings<\/code> \u65b9\u6cd5\u4e2d\u9009\u62e9\u53ef\u4ee5\u5206\u7ec4\u7684\u4ee3\u7801\u3002 \u6211\u4eec\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528\u5feb\u6377\u952e <strong>\u2325\u2318M<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+Alt+M<\/strong> \u5c06\u8fd9\u6bb5\u4ee3\u7801\u63d0\u53d6\u5230\u53e6\u4e00\u65b9\u6cd5\u3002<br \/>\n\u672c\u5757\u6240\u7528\u5c40\u90e8\u53d8\u91cf\u6216\u65b9\u6cd5\u53c2\u6570\u5c06\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u3002 \u8f93\u5165\u65b9\u6cd5\u540d\u79f0\u540e\uff0c\u4f8b\u5982 manipulateStack\uff0c\u6211\u4eec\u63d0\u53d6\u7684\u4ee3\u7801\u5757\u5c31\u4f1a\u88ab\u66ff\u6362\u6210\u65b9\u6cd5\u7684\u8c03\u7528\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/extract_method.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/extract_method.gif\" ><\/p>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u63d0\u53d6\u65b9\u6cd5\uff1a\u9009\u62e9\u4ee3\u7801\uff0c\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2325\u23ce<\/strong> \u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Alt+Enter<\/strong>\uff0c\u7136\u540e\u9009\u62e9 Extract Method\u3002<\/p>\n<h2>\u5185\u8054\u65b9\u6cd5<\/h2>\n<p><a href=\"https:\/\/www.jetbrains.com\/help\/idea\/inline-method.html\" target=\"_blank\" rel=\"noopener\">\u5185\u8054\u65b9\u6cd5\u91cd\u6784<\/a> \u662f Extract Method \u91cd\u6784\u7684\u9006\u8f6c\u3002 \u6211\u4eec\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528\u5feb\u6377\u952e <strong>\u2325\u2318N<\/strong> \uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+Alt+N<\/strong> \u6765\u5185\u8054\u521a\u521a\u521b\u5efa\u7684\u65b9\u6cd5 <code>manipulateStack<\/code>\u3002 \u6211\u4eec\u53ef\u4ee5\u5185\u8054\u65b9\u6cd5\u5185\u5bb9\u7136\u540e\u5220\u9664\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u4fdd\u7559\u65b9\u6cd5\u3002 \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5220\u9664\u4e86\u65b9\u6cd5\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/inline_method.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/inline_method.gif\" ><\/p>\n<p>\u4f46\u4e3a\u4ec0\u4e48\u8981\u5185\u8054\u65b9\u6cd5\u5462\uff1f \u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u6765\u79fb\u9664\u4e0d\u5fc5\u8981\u7684\u91cd\u5b9a\u5411\uff0c\u6216\u8005\u6211\u4eec\u4e5f\u53ef\u80fd\u60f3\u8981\u5185\u8054\u4e25\u91cd\u91cd\u6784\u7684\u65b9\u6cd5\uff0c\u7136\u540e\u518d\u6b21\u63d0\u53d6\u3002<\/p>\n<h2>\u5f15\u5165\u5e38\u91cf<\/h2>\n<p>\u5728\u4ee3\u7801\u5e93\u4e2d\uff0c\u901a\u5e38\u5efa\u8bae\u4f7f\u7528\u5e38\u91cf\u800c\u4e0d\u662f\u6587\u5b57\u503c\uff0c\u90a3\u4e48\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u91cd\u6784\u4ee3\u7801\u4ee5<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-constant.html\" target=\"_blank\" rel=\"noopener\">\u5f15\u5165\u5e38\u91cf<\/a>\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public static boolean beautifulBinaryStrings(String s) {\n    while (!s.equals(s = s.replaceAll(&quot;AA|BB&quot;, &quot;&quot;))) {\n        System.out.println(s);\n    }\n    return s.isEmpty();\n}<\/pre>\n<p>\u6211\u4eec\u7684\u65b9\u6cd5 <code>beautifulBinaryStrings<\/code> \u4f7f\u7528\u5b57\u7b26\u4e32\u6587\u5b57\u503c\u3002 \u6211\u4eec\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528\u5feb\u6377\u952e <strong>\u2325\u2318C<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+Alt+C<\/strong> \u5c06\u8fd9\u4e2a\u503c\u63d0\u53d6\u5230\u5e38\u91cf\u3002<\/p>\n<p>IntelliJ IDEA \u6839\u636e\u6587\u5b57\u503c\u5efa\u8bae\u5e38\u91cf\u540d\u79f0\u3002 \u6211\u4eec\u5c06\u9009\u62e9\u7b2c\u4e00\u4e2a\u5efa\u8bae\u3002 \u6839\u636e\u9700\u8981\uff0c\u60a8\u4e5f\u53ef\u4ee5\u9009\u62e9\u5c06\u8fd9\u4e2a\u5e38\u91cf\u79fb\u5230\u5176\u4ed6\u7c7b\u4e2d\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/intro_constant.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/intro_constant.gif\" ><\/p>\n<h2>\u5f15\u5165\u5b57\u6bb5<\/h2>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u6b64\u91cd\u6784<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-field.html#extract_field_example\" target=\"_blank\" rel=\"noopener\">\u5f15\u5165\u6216\u63d0\u53d6<\/a>\u5b57\u6bb5\u5e76\u5c06\u5176\u521d\u59cb\u5316\u3002<br \/>\n\u6211\u4eec\u7684 <code>ViewImpl<\/code> \u7c7b\u4e2d\u7684\u65b9\u6cd5 <code>getItemsList<\/code> \u4f7f\u7528\u5e38\u91cf 0 \u548c 4 \u6765\u83b7\u53d6\u4e00\u4e2a\u5217\u8868\u7684\u5b50\u96c6\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class ViewImpl implements View {\n   @Override\n   public List&lt;Integer&gt; getItemsList() {\n       return List.of(1, 2, 3, 4, 5).subList(0,4);\n   }\n}<\/pre>\n<p>\u9664\u4e86\u5c06\u5176\u5b9a\u4e49\u4e3a\u5e38\u91cf\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2325\u2318F<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+Alt+F<\/strong> \u6765\u5f15\u5165\u5b57\u6bb5\u5b58\u50a8\u8fd9\u4e9b\u503c\uff0c\u4ee5\u4fbf\u5b83\u4eec\u5728\u4e0d\u540c\u5b9e\u4f8b\u4e2d\u62e5\u6709\u4e0d\u540c\u503c\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/intro_field.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/intro_field.gif\" ><\/p>\n<h2>\u63d0\u53d6\u53c2\u6570<\/h2>\n<p>\u901a\u8fc7 <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-parameter.html\" target=\"_blank\" rel=\"noopener\">Extract Parameter \u91cd\u6784<\/a>\uff0c\u60a8\u53ef\u4ee5\u5728\u65b9\u6cd5\u4e2d\u9009\u62e9\u4e00\u4e2a\u5e38\u91cf\u6216\u8868\u8fbe\u5f0f\uff0c\u5e76\u5c06\u5176\u5b9a\u4e49\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u65b9\u6cd5\u3002 \u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u8fd8\u4e3a <code>getItemsList<\/code> \u65b9\u6cd5\u5f15\u5165\u4e86\u7b2c\u4e8c\u4e2a\u5b57\u6bb5\uff0c\u540d\u4e3a <code>toIndex<\/code>\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class ViewImpl implements View {\n   private final int fromIndex;\n   private final int toIndex;\n\n   public ViewImpl() {\n       fromIndex = 0;\n       toIndex = 4;\n   }\n\n   public List&lt;Integer&gt; getItemsList() {\n       return List.of(1, 2, 3, 4, 5).subList(fromIndex, toIndex);\n   }\n}<\/pre>\n<p>\u5728 <code>getItemsList<\/code> \u65b9\u6cd5\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5c06\u8868\u8fbe\u5f0f <code>List.of(1,2,3,4,5)<\/code> \u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u6b64\u65b9\u6cd5\u3002 \u65b9\u6cd5\u53c2\u6570\u7684\u7c7b\u578b\u4e0e\u6240\u9009\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\u76f8\u540c\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/extract_param_first_option.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/extract_param_first_option.gif\" ><\/p>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u9009\u4e2d Delegate via method overloading \u590d\u9009\u6846\uff0c\u4ee5\u4fdd\u7559\u539f\u59cb\u65b9\u6cd5\u5e76\u5141\u8bb8\u5f15\u5165\u7b2c\u4e8c\u4e2a\u65b9\u6cd5\u3002 \u8fd9\u610f\u5473\u7740\u4efb\u4f55\u4e00\u4e2a\u65b9\u6cd5\u90fd\u53ef\u4ee5\u6839\u636e\u8c03\u7528\u8005\u6765\u4f7f\u7528\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/extract_param_second_option.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/extract_param_second_option.gif\" ><\/p>\n<p>Extract parameter \u53ef\u4ee5\u5e2e\u52a9\u60a8\u5c06\u8868\u8fbe\u5f0f\u79fb\u5230\u6700\u5408\u7406\u7684\u4f4d\u7f6e\uff0c\u4f7f\u65b9\u6cd5\u6216\u65b9\u6cd5\u8c03\u7528\u66f4\u6613\u8bfb\u3002 \u4f7f\u7528\u6613\u4e8e\u7406\u89e3\u7684\u53c2\u6570\u540d\u79f0\u4e5f\u6709\u52a9\u4e8e\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/p>\n<h2>\u5f15\u5165\u53d8\u91cf<\/h2>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-variable.html\" target=\"_blank\" rel=\"noopener\">\u63d0\u53d6\u53d8\u91cf<\/a>\u3002 \u6709\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8868\u8fbe\u5f0f\u79fb\u5230\u4e00\u4e2a\u9002\u5f53\u547d\u540d\u7684\u53d8\u91cf\u4e2d\uff0c\u4f7f\u4ee3\u7801\u66f4\u6613\u8bfb\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public ContextActionsWithAltEnter(double cityPopulation) {\n    if (cityPopulation &gt; 0x1.2016eb678a2p43 &amp;&amp; cityPopulation &lt; 987677.8) {\n        if (cityPopulation % 5 == 0) {\n            this.cityPopulation \/= 2;\n        }\n    }\n    this.cityPopulation = cityPopulation;\n}<\/pre>\n<p><code>ContextActionsWithAltEnter<\/code> \u6784\u9020\u51fd\u6570\u4e2d\u7684 <code>if<\/code> \u8bed\u53e5\u770b\u8d77\u6765\u6709\u4e9b\u590d\u6742\u3002 \u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u8868\u8fbe\u5f0f\uff0c\u5728 macOS \u4e0a\u4f7f\u7528 <strong>\u2325\u2318V<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Ctrl+Alt+V<\/strong>\u3002 \u786e\u4fdd\u7ed9\u5b83\u8d77\u4e00\u4e2a\u6709\u7528\u7684\u540d\u5b57\uff0c\u5982 <code>lowerLimit<\/code>\u3002 \u6211\u4eec\u4e5f\u53ef\u4ee5\u5c06\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u63d0\u53d6\u5230\u4e00\u4e2a\u53d8\u91cf\u4e2d\uff0c\u5e76\u5c06\u5176\u547d\u540d\u4e3a <code>upperLimit<\/code>\u3002 \u6839\u636e\u9700\u8981\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u5c06\u63d0\u53d6\u7684\u53d8\u91cf\u5b9a\u4e49\u4e3a <code>final<\/code>\uff0c\u5982\u679c\u4f7f\u7528\u7684\u662f Java 10 \u6216\u66f4\u9ad8\u7248\u672c\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4e3a <code>var<\/code>\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-55173 size-full\" style=\"border: 1px solid #AAAAAA;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/introduce_variable.png\" alt=\"Refactor variable name\" width=\"750\" height=\"300\" data-gif-src=\"https:\/\/resources.jetbrains.com\/storage\/products\/blog\/wp-content\/uploads\/Java\/introduce_variable.gif\" ><\/p>\n<p>\u8868\u8fbe\u5f0f\u73b0\u5728\u770b\u8d77\u6765\u663e\u7136\u66f4\u6613\u8bfb\u4e86\u3002<\/p>\n<h2>\u5b89\u5168\u5220\u9664<\/h2>\n<p>\u5982\u679c\u60a8\u4e0d\u60f3\u518d\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u67d0\u4e2a\u6587\u4ef6\u6216\u7b26\u53f7\uff0c\u60a8\u5e94\u8be5\u628a\u5b83<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/safe-delete.html\" target=\"_blank\" rel=\"noopener\">\u5b89\u5168\u5220\u9664<\/a>\u3002<\/p>\n<p>\u9009\u62e9\u8981\u5220\u9664\u7684\u6587\u4ef6\u6216\u7c7b\uff0c\u7136\u540e\u4f7f\u7528 <strong>\u2318\u2326<\/strong>\uff0c\u6216\u8005\u5728 Windows\/Linux \u4e0a\u4f7f\u7528 <strong>Alt+Delete<\/strong>\u3002 IntelliJ IDEA \u5728\u786e\u4fdd\u8d44\u6e90\u53ef\u88ab\u5b89\u5168\u5220\u9664\u4e4b\u540e\u624d\u4f1a\u5c06\u5176\u5220\u9664\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/08\/safe_delete.png\" alt=\"Safe Delete\" \/><\/p>\n<h2>\u5c0f\u7ed3<\/h2>\n<p>IntelliJ IDEA \u5177\u6709\u5f3a\u5927\u7684\u91cd\u6784\u529f\u80fd\uff0c\u60a8\u65e5\u5e38\u53ef\u4ee5\u5b89\u5168\u5730\u7528\u5b83\u6765\u6539\u8fdb\u4ee3\u7801\u3002<br \/>\n\u4e0d\u8fc7\uff0c\u91cd\u6784\u5e76\u4e0d\u662f\u7075\u4e39\u5999\u836f\u3002 \u8bf7\u5efa\u7acb\u4e00\u4e2a\u6d4b\u8bd5\u7684\u5b89\u5168\u7f51\uff0c\u786e\u4fdd\u60a8\u7684\u91cd\u6784\u4e0d\u4f1a\u6539\u53d8\u4ee3\u7801\u884c\u4e3a\u3002<\/p>\n<p>\u8fd8\u6709\u66f4\u591a\u5185\u5bb9\uff1a<br \/>\n<a href=\"https:\/\/www.jetbrains.com\/help\/idea\/refactoring-source-code.html#1078e\" target=\"_blank\" rel=\"noopener\">IntelliJ IDEA \u4e2d\u652f\u6301\u7684\u6700\u70ed\u95e8\u91cd\u6784<\/a><br \/>\n<a href=\"https:\/\/blog.jetbrains.com\/idea\/2019\/07\/refactoring-inline-method-in-intellij-idea\/\">\u91cd\u6784\uff1a\u5728 IntelliJ IDEA \u4e2d\u5185\u8054\u65b9\u6cd5<\/a><br \/>\n<a href=\"https:\/\/blog.jetbrains.com\/idea\/2019\/04\/refactoring-extract-variable-in-intellij-idea\/\">\u91cd\u6784\uff1a\u5728 IntelliJ IDEA \u4e2d\u63d0\u53d6\u53d8\u91cf<\/a><\/p>\n","protected":false},"author":814,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","categories":[],"tags":[],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/77374"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/types\/idea"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/users\/814"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=77374"}],"version-history":[{"count":3,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/77374\/revisions"}],"predecessor-version":[{"id":77547,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/idea\/77374\/revisions\/77547"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=77374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=77374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=77374"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/cross-post-tag?post=77374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}