forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.java
More file actions
61 lines (50 loc) · 1.19 KB
/
Copy pathExample2.java
File metadata and controls
61 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package chapter_08;
import java.util.Arrays;
import java.util.List;
/**
* if else 块的顺序
*
* @author biezhi
* @date 2018/7/11
*/
public class Example2 {
boolean a, b;
public void part1() {
// if (a == b) {
// System.out.println("有钱人");
// } else {
// System.out.println("没钱的肥宅");
// }
if (a != b) {
System.out.println("没钱的肥宅");
} else {
System.out.println("有钱人");
}
}
class Request {
boolean hasParam(String key) {
return false;
}
}
class Response {
void writeJSON(Object bean) {
}
}
public void part2(Request request, Response response) {
List<String> items = Arrays.asList("hello", "world");
// if (!request.hasParam("biezhi")) {
// response.writeJSON(items);
// } else {
// for (String item: items) {
// // TODO
// }
// }
if (request.hasParam("biezhi")) {
for (String item: items) {
// TODO
}
} else {
response.writeJSON(items);
}
}
}