How can I get the type automatically of returned object for method using hotkeys in Intellij IDEA?
Quite often there are times when you need to modify such line:
myinstance.getMyMethod();
in the following:
IMySomeObject mysomeobject = myinstance.getMySomeObject();
I wish that IDEA did it itself for me to save time. I do not wish to explore method's signature, find its returned type and manually create this reference with a specific type of returned object. It's not convenient.
Choose Navigate | Go to Declaration in the main menu, press F12 , or click the symbol while holding the Ctrl key.
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
Using the Introduce Variable refactor.
Select
myinstance.getMyMethod();
press <ctrl>+<alt> + V and you will see a selections of names to give it like
IMySomeObject mySomeObject = myinstance.getMySomeObject();
I then select <Enter> as the first option is usually fine.
I suggest you have a look at all the refactoring tools in the Refactor Menu and learn what they all do.
You can type m
then type .
then <Enter>
then press <ctrl> + <alt> + V
lastly press <Enter> to accept the default 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