[6주차] 이예림_item 44#32
Merged
023-dev merged 2 commits intoeffective-java-3e-study:mainfrom Feb 20, 2025
Merged
Conversation
DanielYY95
reviewed
Feb 14, 2025
Contributor
There was a problem hiding this comment.
이 부분이 잘 이해가 되지않아서, 혹시 예시 같은 것을 통해 좀 더 추가 설명가능할까요?
Contributor
Author
There was a problem hiding this comment.
public static void main(String[] args) {
Function<Integer, Integer> square = x -> x * x; // Integer → Integer
int result = square.apply(5);
System.out.println(result);
}해당 예시를 참고해봐주시면 좋을 것 같습니다. 지금 입력값(Integer x)을 받아서 x * x를 계산한 뒤 Integer로 반환하는 함수 객체를 만들고, square.apply(5) 를 호출하였습니다.
int값으로 들어간 5는Integer로 오토박싱- 연산 수행
(x * x)시,Integer이 언박싱 되어 다시int로 변환 - 다시 오토박싱 되어
Integer(25)결과 출력
따라서 박싱과 언박싱이 불필요하게 여러 번 일어나서 성능이 저하될 가능성이 있다고 합니다.
덕분에 저도 더 상세히 생각해 볼 수 있었습니다. 질문해 주셔서 감사합니다:)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.