且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有在Eclipse中向现有构造函数添加字段的快捷方式?

更新时间:2023-01-31 12:09:19

我会首先使用更改方法签名重构(mac上的选项+命令+ c)将额外参数添加到构造函数中。这样,调用构造函数的现有代码可以将合理的默认值作为参数传递(如果您愿意)。然后按CTRL + 1选择多次,以便按照建议将新字段快速修复到课程中。

I would use the "change method signature" refactoring first (option+command+c on mac) to add the extra parameter(s) to the constructor. This way existing code that calls the constructor can pass sensible default as parameters (if you like). Then choose as many times CTRL+1 to quick fix the new fields into the class as you suggested.