Question
How can the var keyword be automatically replaced with the explicit type in project files when saving the source code in the IntelliJ IDE?
Example
var product = new Product();
Desired result upon saving the code:
Product product = new Product();
Answer
-
Go to main menu > Code > Analyze Code > 'Run inspection by name'
-
Find the inspection called "Variable type can be explicit" and double-click it or hit Enter to choose it
-
In the dialog that opens, select the scope to run the inspection on and click 'Analyze'
-
In the Problems tool window that opens, click on each found item to review it and apply the quick fix, or right-click the inspection results parent node and choose "Replace 'var' with explicit type" to apply the fix for all files at once
If you want to run this inspection on each file save, you can enable the option to "Run code cleanup" in File | Settings | Tools | Actions on Save, and configure the scope from there.
For more information, see:
Comments
0 comments
Please sign in to leave a comment.