1.9. Completing Code Automatically
Problem
While entering code, you forgot the name of either a method you wanted to call or some of a method’s parameters.
Solution
Use Eclipse’s code assist (also
called content assist) to
help out. When you
enter the name of an object or class in the JDT code editor followed
by a period (.) and then pause, code assist
displays the members of that object or class, and you can select the
one you want. You also can bring up code assist at any time (e.g.,
when you’ve positioned the cursor inside a
method’s parentheses, and you want to see what
arguments that method takes) by pressing Ctrl-Space or by selecting
Edit→ Content Assist.
Discussion
Code (or content) assist is one of the good things about using a full Java IDE. It’s an invaluable tool that accelerates development, and it’s a handy resource that you’ll probably find yourself relying on in time. In the code example we’ve been developing over the previous few recipes, enter the following code to display some text:
public class FirstApp
{
public static void main(String[] args)
{
System.out.println("Stay cool.");
}
}To work with code assist, enter System. in the
main method of the FirstApp
project, then pause. Code assist displays the classes and methods in
the System namespace, as shown in Figure 1-11.

Figure 1-11. Using code assist
Double-click out in the code assist list so that code assist inserts ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access