forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
41 lines (32 loc) · 963 Bytes
/
Copy pathExample3.java
File metadata and controls
41 lines (32 loc) · 963 Bytes
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
package chapter_02;
import java.util.HashMap;
import java.util.Map;
/**
* @author biezhi
* @date 2018/6/24
*/
public class Example3 {
private Map<String, Coder> coderMap = new HashMap<String, Coder>();
public Example3() {
coderMap.put("biezhi", new Coder(true));
coderMap.put("80k", new Coder(false));
}
private Coder findCoder(String key) {
return coderMap.get(key);
}
public void before() {
Coder coder;
boolean hasGirlFriend = (null != (coder = findCoder("biezhi"))) && coder.hasGirlFriend();
System.out.println("是否有女朋友: " + hasGirlFriend);
}
public void after() {
Coder coder = this.findCoder("biezhi");
if(null != coder){
System.out.println("是否有女朋友: " + coder.hasGirlFriend());
}
}
public static void main(String[] args) {
new Example3().before();
new Example3().after();
}
}