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
Thanks, we've got you!
Profile on the Fly With the IntelliJ Profiler
At JetBrains, we believe that profiling 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 range of features to s…
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…
How to Work With Protobuf-Maven Projects in IntelliJ IDEA
Protobuf, short for Protocol Buffers, is a language-agnostic data serialization format developed by Google. It is designed to efficiently and reliably serialize structured data to communicate between different systems and programming languages. Protobuf offers a compact binary representation of data…
Turbocharge Lombok annotations with IntelliJ IDEA
If you’re a professional Java developer, you probably use IntelliJ IDEA as your IDE and Lombok as the framework that handles the Java boilerplate. What you probably didn’t know is that not only do these 2 technologies work well on their own, but when combined, they’re even more efficient than when u…