提交 a3baf538 编写于 作者: ishellhub's avatar ishellhub

format code

上级 814bda6b
...@@ -51,10 +51,7 @@ public class Pizza { ...@@ -51,10 +51,7 @@ public class Pizza {
} }
public boolean isDeliverable() { public boolean isDeliverable() {
if (getStatus() == PizzaStatus.READY) { return getStatus() == PizzaStatus.READY;
return true;
}
return false;
} }
// Methods that set and get the status variable. // Methods that set and get the status variable.
...@@ -63,9 +60,9 @@ public class Pizza { ...@@ -63,9 +60,9 @@ public class Pizza {
## 3.使用 == 比较枚举类型 ## 3.使用 == 比较枚举类型
由于枚举类型确保JVM中仅存在一个常量实例,因此我们可以安全地使用“ ==”运算符比较两个变量,如上例所示;此外,“ ==”运算符可提供编译时和运行时的安全性。 由于枚举类型确保JVM中仅存在一个常量实例,因此我们可以安全地使用 `==` 运算符比较两个变量,如上例所示;此外,`==` 运算符可提供编译时和运行时的安全性。
首先,让我们看一下以下代码段中的运行时安全性,其中“ ==”运算符用于比较状态,并且如果两个值均为null 都不会引发 NullPointerException。相反,如果使用equals方法,将抛出 NullPointerException: 首先,让我们看一下以下代码段中的运行时安全性,其中 `==` 运算符用于比较状态,并且如果两个值均为null 都不会引发 NullPointerException。相反,如果使用equals方法,将抛出 NullPointerException:
```java ```java
if(testPz.getStatus().equals(Pizza.PizzaStatus.DELIVERED)); if(testPz.getStatus().equals(Pizza.PizzaStatus.DELIVERED));
...@@ -84,9 +81,12 @@ if(testPz.getStatus() == TestColor.GREEN); ...@@ -84,9 +81,12 @@ if(testPz.getStatus() == TestColor.GREEN);
```java ```java
public int getDeliveryTimeInDays() { public int getDeliveryTimeInDays() {
switch (status) { switch (status) {
case ORDERED: return 5; case ORDERED:
case READY: return 2; return 5;
case DELIVERED: return 0; case READY:
return 2;
case DELIVERED:
return 0;
} }
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册