Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse?

前端 未结 7 2095
无人及你
无人及你 2020-12-04 09:43

In Eclipse, while coding in Java and press Ctrl + Shift + O auto import all the Classes automatically.
In NetBeans, this is done with

相关标签:
7条回答
  • 2020-12-04 10:24

    Use control+option+L to auto import the package and auto remove unused packages on Mac

    0 讨论(0)
  • 2020-12-04 10:25

    Not all at once. But you can press

    Alt + Enter

    People assume it only works when you are at the particular item. But it actually works for "next missing type". So if you keep pressing Alt + Enter, IDEA fixes one after another until all are fixed.

    0 讨论(0)
  • 2020-12-04 10:26

    Another option is to ask IDEA to behave like eclipse with eclipse shortcut keys. You can use all eclipse shortcuts by enabling this.

    Here are the steps:

    1- With IDEA open, press Control + `. Following options will be popped up.

    2- Select Keymap. You will see another pop-up. Select Eclipse there.

    3- Now press Ctrl + Shift + O. You are done!

    0 讨论(0)
  • 2020-12-04 10:28

    I think the best solution, though not exactly the same as Eclipse/Netbeans, is to change the 'Optimize Imports' settings.

    Under Preferences > Editor > General > Auto Import

    Set Add unambiguous imports on the fly

    Edit: Using this method, when there are ambiguous imports, IntelliJ will let you know, and you can then use Alt + Enter method outlined in the answer by Wuaner

    I find that, almost always, the most appropriate Import is at the top of the list.

    0 讨论(0)
  • 2020-12-04 10:34

    Can't import all at once but can use following combination:

    ALT + Enter --> Show intention actions and quick-fixes.

    F2 --> Next highlighted error.

    0 讨论(0)
  • 2020-12-04 10:36

    Seems like IntelliJ IDEA will import missed class automatically, and you can import them by hit Alt + Enter manually.

    0 讨论(0)
提交回复
热议问题