Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

java - How to make eclipse automatically add braces to an IF statement?

In Java the following is completely valid:

if (x == null)
    Y();
else
    Z();

I personally don't like it at all. I like all my IF statements to have braces:

if (x == null) {
    Y();
} else {
    Z();
}

The eclipse formatter is wonderful and can beautify my code in many other ways.

Is there a way to have it add the braces to IF statements?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Under "Preferences": Java > Editor > Save Actions

1) Check "Additional actions"

2) Click "Configure…"

3) Go to the "Code Style" tab

4) Check "Use blocks in if/while/for/do statements" and configure to your preferences


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...