I write:
x = getFoo();
How can I get IDEA to turn this into:
Foo x = getFoo();
? IDEA certainly knows what the return type of getFoo
is, but it refuses to auto-complete it.
The documentation says that Ctrl+Shift+Space
should work, but it doesn't.
By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again. This lets you complete:
We can press Alt+Enter at the end of this and have IntelliJ IDEA create a valid variable declaration for us. We even get useful defaults suggested for variable names. Even as we’re typing our variable declaration, IntelliJ IDEA will suggest types and names for us.
IntelliJ IDEA creates a new public static final constant at the start of our class: IntelliJ IDEA also replaces the original line of code with the new constant: System.out.println ("Number of times the planet rotates around the sun is " + NUMBER_OF_DAYS_IN_A_YEAR);
If basic code completion is applied to a part of a field, parameter, or variable declaration, IntelliJ IDEA suggests a list of possible names depending on the item type.
Use the postfix code completion feature instead. What you would write is getFoo().var
, and this will auto-expand it to the type and let you modify the variable name.
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