-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
35 lines (26 loc) · 792 Bytes
/
App.java
File metadata and controls
35 lines (26 loc) · 792 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
package kr.springboot.examples.ex14;
import java.util.Objects;
import java.util.Optional;
/**
* Do Not Use Optional in Constructors Arguments
* 생성자 인수에서 옵셔널을 사용하지 마랏
*/
public class App {
private final String name;
// Avoid
private final Optional<String> postCodeAvoid;
// Avoid
public App(String name, Optional<String> postCode) {
this.name = Objects.requireNonNull(name, () -> "이름은Null일수없음.");
this.postCodeAvoid = postCode;
postCodePrefer = null;
}
// Prefer
private final String postCodePrefer;
// Prefer
public App(String name, String postCodePrefer) {
this.name = name;
this.postCodePrefer = postCodePrefer;
postCodeAvoid = null;
}
}