-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
44 lines (27 loc) · 963 Bytes
/
App.java
File metadata and controls
44 lines (27 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
42
43
44
package kr.springboot.examples.ex26;
import kr.springboot.examples.commons.Cart;
import java.util.Optional;
/**
* Return a boolean If The Optional Is Empty. Prefer Java 11, Optional.isEmpty()
* Optional 이 비어 있으면 Boolean 을 반환하자 / Java 11 이상 Optional.isEmpty() 선호
*/
public class App {
// Avoid
public Optional<String> fetchCartItemsAvoid(long id) {
String cart = null ; // this may be null
return Optional.ofNullable(cart);
}
public boolean cartIsEmptyAvoid(long id) {
Optional<String> cart = fetchCartItemsAvoid(id);
return !cart.isPresent();
}
// Prefer
public Optional<String> fetchCartItemsPrefer(long id) {
String cart = null ; // this may be null
return Optional.ofNullable(cart);
}
public boolean cartIsEmptyPrefer(long id) {
Optional<String> cart = fetchCartItemsPrefer(id);
return cart.isEmpty();
}
}