Something more about completion
Along with basic code completion already described on this blog, IntelliJ IDEA provides so-called “smart completion” that can be considered as a separate feature. Sometimes users call it “super” or even “secret” completion. “Super” is because this feature is far more intelligent than simple completion. “Secret” comes from the fact that this completion is invoked not by the usual Ctrl + Space shortcut, but by Ctrl + Shift + Space.
Why have two different completions? Well, how often have you found yourself saying “This thing thinks that it’s smarter than me!” and try to make the product do what you want it to do? IntelliJ IDEA doesn’t want to be smarter than you are. But its intelligence is always at your disposal when you need it.
So, what is so special about smart completion? First of all, it filters the list of suggestions according to the expected expression type.
For example, it can suggest values at right-hand side of assignments, in the return statements, in method calls, and anywhere you need to.
In obvious cases where you don’t need to see a list of choices, smart completion will simply add the necessary value. For example, use Ctrl + Shift + Space after new when you create an instance of a class.
IntelliJ IDEA adds the constructor, brackets, and the semicolon. It also positions the caret right within the brackets. And all you need to do is press Ctrl + Shift + Space again to see the list of possible parameter values.
In case of abstract classes and interfaces, you can choose one of the inheritors.
Another example when you don’t need a list of choices is type casting. For example, you have typed something like str = (, where str is some variable of String type. To cast the right-hand side of assignment to String, just press Ctrl + Shift + Space. The result, of course, will be str = (String).
But, probably, the most impressive use case for the Smart completion is when you create an anonymous implementation of some interface. For example, you had the following code:
When you press Ctrl + Shift + Space and select the MouseListener interface, you get the following result:
Just think about the time the smart completion saves.
Note This tip&trick was originally posted at www.javalobby.org.
Subscribe to Blog updates
Java Best Practices
Good code follows certain rules, and knowing them increases your chances of success. We’d like to share some Java best practices that will help you on your way. We'll cover the must-know tips and tricks, from broad advice on software development to Java- and project-specific know-how. Let's get star…
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Profile Java and Kotlin Code with the IntelliJ Profiler
At JetBrains, we believe that profiling Java and Kotlin code should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission. In previous releases, we introduced a r…
History of Gradle Delegation Process in IntelliJ IDEA
Nowadays, a build tool is an essential part of any project, and IntelliJ IDEA integrates with the majority of them. Among the most popular build tools is Gradle. We’d like to give a brief historical overview of its integration with IntelliJ IDEA and the delegation process implemented inside the I…