📢주어진 조건📢
int n = 1;
Function<Integer, String> conv = from -> String.valueOf(from + n);
n = 3;
String s = conv.apply(2);
🧤정답🧤
변수 n은 사실상 final이어야 하기 때문에 값을 변하게 해주는 n =3; 때문에 오류가 발생.
10.다음 코드의 실행 결과는 무엇인가?
📢주어진 조건📢
Function<Integer, Integer> f = x -> x + 2;
Function<Integer, Integer> g = x -> x * 2;
Function<Integer, Integer> h = f.compose(g);
System.out.println(h.apply(3));
🧤정답🧤
8
해설 :
compose는 역방향으로 진행되기 때문에 3 * 2를 한 후 + 2를 하기 때문에 8이 된다.