We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 26a8c8d commit 80f1e07Copy full SHA for 80f1e07
java/함수적인터페이스-supplier.md
@@ -0,0 +1,30 @@
1
+## 관련 링크
2
+
3
+[관련 링크](https://cornswrold.tistory.com/308)
4
5
+## 공부한 내용
6
7
+### supplier에 대해 알게 되었다.
8
9
+java Optional method에 대해 공부하던 중 .orElseGet()에 대해 알게 되었다.
10
11
+내부 코드를 보니 인자로 supplier를 받는 것을 볼 수 있었다.
12
+관련 코드는 다음과 같다.
13
14
+```java
15
+ public T orElseGet(Supplier<? extends T> supplier) {
16
+ return this.value != null ? this.value : supplier.get();
17
+ }
18
19
+ public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
20
+ if (this.value != null) {
21
+ return this.value;
22
+ } else {
23
+ throw (Throwable)exceptionSupplier.get();
24
25
26
+```
27
28
+내부 코드에서는 제네릭을 활용해 상속받은 모든 것들을 활용할 수 있게 만들어보인다.
29
30
+여기서 Supplier는 인자없는 함수코드를 실행해준다. 또한 함수형이기에 lazy연산도 가능하다.
0 commit comments