Skip to content

Commit a3baf53

Browse files
format code
1 parent 814bda6 commit a3baf53

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/java/basic/用好Java中的枚举真的没有那么简单.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public class Pizza {
5151
}
5252

5353
public boolean isDeliverable() {
54-
if (getStatus() == PizzaStatus.READY) {
55-
return true;
56-
}
57-
return false;
54+
return getStatus() == PizzaStatus.READY;
5855
}
5956

6057
// Methods that set and get the status variable.
@@ -63,9 +60,9 @@ public class Pizza {
6360

6461
## 3.使用 == 比较枚举类型
6562

66-
由于枚举类型确保JVM中仅存在一个常量实例,因此我们可以安全地使用“ ==”运算符比较两个变量,如上例所示;此外,“ ==”运算符可提供编译时和运行时的安全性。
63+
由于枚举类型确保JVM中仅存在一个常量实例,因此我们可以安全地使用 `==` 运算符比较两个变量,如上例所示;此外,`==` 运算符可提供编译时和运行时的安全性。
6764

68-
首先,让我们看一下以下代码段中的运行时安全性,其中“ ==”运算符用于比较状态,并且如果两个值均为null 都不会引发 NullPointerException。相反,如果使用equals方法,将抛出 NullPointerException:
65+
首先,让我们看一下以下代码段中的运行时安全性,其中 `==` 运算符用于比较状态,并且如果两个值均为null 都不会引发 NullPointerException。相反,如果使用equals方法,将抛出 NullPointerException:
6966

7067
```java
7168
if(testPz.getStatus().equals(Pizza.PizzaStatus.DELIVERED));
@@ -84,9 +81,12 @@ if(testPz.getStatus() == TestColor.GREEN);
8481
```java
8582
public int getDeliveryTimeInDays() {
8683
switch (status) {
87-
case ORDERED: return 5;
88-
case READY: return 2;
89-
case DELIVERED: return 0;
84+
case ORDERED:
85+
return 5;
86+
case READY:
87+
return 2;
88+
case DELIVERED:
89+
return 0;
9090
}
9191
return 0;
9292
}

0 commit comments

Comments
 (0)