public enum RightCurlyOption extends Enum<RightCurlyOption>
'}'.| Enum Constant and Description |
|---|
ALONE
Represents the policy that the brace must be alone on the line.
|
ALONE_OR_SINGLELINE
Represents the policy that the brace must be alone on the line,
yet allows single-line format of block.
|
SAME
Represents the policy that the brace should be on the same line as the
the next part of a multi-block statement (one that directly contains
multiple blocks: if/else-if/else or try/catch/finally).
|
| Modifier and Type | Method and Description |
|---|---|
static RightCurlyOption |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static RightCurlyOption[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final RightCurlyOption ALONE_OR_SINGLELINE
// Brace is alone on the line
try {
...
}
finally {
...
}
// Single-line format of block
public long getId() { return id; }
public static final RightCurlyOption ALONE
try {
...
}
finally {
...
}
public static final RightCurlyOption SAME
Examples:
// try-catch-finally blocks
try {
...
} catch (Exception ex) { // this is OK
...
} finally { // this is OK
...
}
try {
...
} // this is NOT OK, not on the same line as the next part of a multi-block statement
catch (Exception ex) {
...
} // this is NOT OK, not on the same line as the next part of a multi-block statement
finally {
...
}
// if-else blocks
if (a > 0) {
...
} else { // this is OK
...
}
if (a > 0) {
...
} // this is NOT OK, not on the same line as the next part of a multi-block statement
else {
...
}
if (a > 0) {
...
} int i = 5; // this is NOT OK, next part of a multi-block statement is absent
// Single line blocks will rise violations, because right curly
// brace is not on the same line as the next part of a multi-block
// statement, it just ends the line.
public long getId() {return id;} // this is NOT OK
Thread t = new Thread(new Runnable() {
@Override
public void run() {
...
} // this is NOT OK, not on the same line as the next part of a multi-block statement
}); // this is OK, allowed for better code readability
if (a > 0) { ... } // OK, single-line multi-block statement
if (a > 0) { ... } else { ... } // OK, single-line multi-block statement
if (a > 0) {
...
} else { ... } // OK, single-line multi-block statement
public static RightCurlyOption[] values()
for (RightCurlyOption c : RightCurlyOption.values()) System.out.println(c);
public static RightCurlyOption valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullCopyright © 2001–2018. All rights reserved.