Summary: | Generate Constructor: generate useful constructor instead of default constructor | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Roland Illig <rillig> |
Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
Status: | NEW --- | QA Contact: | |
Severity: | enhancement | ||
Priority: | P3 | CC: | stephan.herrmann |
Version: | 4.6 | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: |
Description
Roland Illig
2016-06-03 04:38:21 EDT
Are you aware of the following commands? Source > Generate Getters and Setters Source > Generate Constructor using Fields They seem to do exactly what you request. Just these commands are not suitable for Ctrl+Space because user input is required for selecting various options. Off-topic: (In reply to Roland Illig from comment #0) > [...] and now I need to add all the boilerplate code that Java requires: > [..] > * the getters > * the setters Java doesn't require getters and setters, it's so-called "best practice", nothing more. The following classes are fully equivalent: final class Foo1 { private String val; public void setVal(String val) { this.val = val; } public String getVal() { return this.val; } } final class Foo2 { public String val; } The choice is your's :) (In reply to Stephan Herrmann from comment #1) > Are you aware of the following commands? > > Source > Generate Getters and Setters > > Source > Generate Constructor using Fields > > They seem to do exactly what you request. Just these commands are not > suitable for Ctrl+Space because user input is required for selecting various > options. I am aware of these commands, but they feed too far away from the code I’m currently editing. I’m focused on typing on the keyboard, and these commands currently require me to nagivate through the menus, open some large dialogs and require me to do several choices. I think most of these choices are normally not necessary. That’s why I would like the Ctrl+Space menu to be extended with generating a _suitable_ constructor instead of the default one. And while here, I thought it would be nice if Eclipse generated the getters and setters along the way. > Off-topic: > > (In reply to Roland Illig from comment #0) > > [...] and now I need to add all the boilerplate code that Java requires: > > [..] > > * the getters > > * the setters > > Java doesn't require getters and setters, it's so-called "best practice", > nothing more. Shouldn’t Eclipse make it easy for Java developers to follow so-called “best practice”? ;) And, by the way, Java is not the programming language alone, it is also the frameworks and common sense around that language. At _that_ requires me to write getters and setters. > The following classes are fully equivalent: > final class Foo1 { > private String val; > public void setVal(String val) { this.val = val; } > public String getVal() { return this.val; } > } > > final class Foo2 { > public String val; > } If they were fully equivalent, Java would be a great language. But they are not. I cannot use the second class in JSPs and several other technologies. > The choice is your's :) No, it isn’t. I’m bound to the frameworks that my projects have chosen several years ago. Therefore I am required to have all this boilerplate in my code. It would be nice of Eclipse to support me doing this boring coding. |