Does Intellij have any way of auto-creating constructor calls, based on the parameters from the constructor's signature?
The idea is that I type the name of class (constructor name), hit Magic+Key+Combination, choose the relevant constructor, and IntelliJ types in all the parameters, based on the names in the constructor's signature. Obviously, in most cases, that wouldn't compile but that's OK, as I will create the required parameters with the appropriate names.
An even better idea would be for the feature to also create the parameter definitions for me, right above the constructor call.
Any Idea?
A Java class constructor initializes instances (objects) of that class. Typically, the constructor initializes the fields of the object that need initialization. Java constructors can also take parameters, so fields can be initialized in the object at creation time.
If I speak technically “Yes” constructor can have any number of parameters.
You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .
I'm an Eclipse user recently migrated into IntelliJ and that was one of the features I really missed, esp. when there are calls with many parameters (not just constructors). As long as there are matching variables in scope, ctrl-shift-space is somewhat similar. It's not quite as good as in Eclipse because if the variables are not there it will not create "stubs", and I don't think it works if the parameter names don't match, but works as a crutch in at least some cases...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With