-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
31 lines (20 loc) · 751 Bytes
/
App.java
File metadata and controls
31 lines (20 loc) · 751 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
package kr.springboot.examples.ex5;
import java.util.NoSuchElementException;
import java.util.Optional;
/**
* When No Value Is Present, Throw a java.util.NoSuchElementException Exception Via orElseThrow() Since Java 10
* 값이 없으면 orElseThrow()를 통해 java.util.NoSuchElementException 예외를 던져라 / Java 10 이상
*/
public class App {
// Avoid
public String findUserStatusAvoid(Long id) {
Optional<String> status = Optional.empty();
if (status.isPresent()) return status.get();
else throw new NoSuchElementException();
}
// Prefer
public String findUserStatusPrefer(Long id) {
Optional<String> status = Optional.empty();
return status.orElseThrow();
}
}