-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
39 lines (31 loc) · 1.1 KB
/
App.java
File metadata and controls
39 lines (31 loc) · 1.1 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
package kr.springboot.examples.ex20;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
/**
* Avoid Optional <T> and Choose Non-Generic OptionalInt, OptionalLong, or OptionalDouble
* 선택적 <T>를 피하고 일반이 아닌 OptionalInt, OptionalLong 또는 OptionalDouble을 선택하자
*/
public class App {
/**
* Avoid example은 Boxing 과 Unboxing의 문제로 성능을 저하시키고 값비싼 작업임.
* 좋은 예와 안좋은 예를 보자
*/
// Avoid
public void avoidExample() {
Optional<Integer> priceInteger = Optional.of(50);
Optional<Long> priceLong = Optional.of(50L);
Optional<Double> priceDouble = Optional.of(50.43d);
}
//Prefer
public void preferExample() {
OptionalInt priceInt = OptionalInt.of(50);
OptionalLong priceLong = OptionalLong.of(50L);
OptionalDouble priceDouble = OptionalDouble.of(50.43d);
// 사용법
priceInt.getAsInt();
priceLong.getAsLong();
priceDouble.getAsDouble();
}
}