Quick Fixes

Whenever you make a syntax error in your program, Eclipse's background compiler detects it immediately and draws an error indicator (affectionately known as the red squiggle) under the offending code. In addition to simply detecting the problem, Eclipse can usually offer an automatic program correction, called a quick fix.

For example, try misspelling the System.out method println as printline. Press Ctrl+1 (Edit → Quick Fix) to see several possible fixes. One of them will be Change to println(..). Press the down arrow to see a preview of each proposed change; press Enter to accept the one you want.

The Quick Fix command can also make suggestions for small source transformations on lines that don't have errors. For example, if you have code like this:

            if (!(hail || thunder))

and you select the text (!(hail || thunder) and press Ctrl+1, Eclipse will suggest some possible transformations, such as "Push negation down." Choosing that particular option would change the code to:

            if (!hail && !thunder)

Get Eclipse IDE Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.