Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto fill stub parameters for constructors in Intellij

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?

like image 974
summerbulb Avatar asked Mar 23 '15 13:03

summerbulb


People also ask

Can constructors take input parameters?

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.

Can constructors have any number of parameters?

If I speak technically “Yes” constructor can have any number of parameters.

How do I select all constructors in IntelliJ?

You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .


1 Answers

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...

like image 161
Lili Avatar answered Sep 17 '22 06:09

Lili