It is permissible to remove braces in case they are superfluous. This not only
applies to the control statements if, for,
while and do-while,
but also to every block in general (remember a block is just a sequence of
statements, local class declarations and local variable declaration statements
within braces). Inserting and removing braces is mutually exclusive.
When enabled, braces around the body of single
if statements are removed when possible.
Since 1.9.1
Example 2.65. Brace removal for single if statements
if (true) { break; }
would become
if (true) break;
When enabled, braces around the body of
if...else statements are removed when possible.
Example 2.66. Brace removal for if statements
if (true) { break; } else { return; }
would become
if (true) break; else return;
When enabled, braces around the body of
for statements are removed when possible.
Example 2.67. Brace removal of for statements
for (int i = 0; i < count; i++) { System.out.println(i); }
would become
for (int i = 0; i < count; i++) System.out.println(i);
When enabled, braces around the body of
while statements are removed when possible.
Example 2.68. Brace removal for while statements
while (!isDone) {
doSomething();
}
would become
while (!isDone)
doSomething();
When enabled, braces around the body of
do...while statements are removed when possible.
Example 2.69. Brace removal for do...while statements
do { something(); } while (condition);
would become
do something(); while (condition);
When enabled, braces are removed around the body of labeled statements inside switch blocks when possible.
Since 1.8
Example 2.70. Brace removal for switch
switch (c) { case 'a': case 'b': { System.out.println(); break; } }
would become
switch (c) { case 'a': case 'b': System.out.println(); break; }
When enabled, arbitrary block braces are removed when possible.