Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[item 53] 영준님이 궁금해 하셨던 List.of()의 비밀 파헤치기🗝️ #86

Open
Jiyeong-github opened this issue Dec 1, 2022 · 0 comments
Labels
👍 Additional 추가로 공부하고 공유한 내용입니다.

Comments

@Jiyeong-github
Copy link
Contributor

영준님이 알고 싶으신 List.of()의 비밀🗝️


링크

주의 자바 9까지만 해도 파라미터 3개가 넘어가면 ListN으로 나왔는데, 자바 11부터는 10개부터라고 함!

왜 list.of() 메소드 파라미터가 3개 이상이면 ImmutableCollections$ListN이 될까?


제가 이해한 거 👉 이렇게 일정 파라미터 이상 호출 시 ListN으로 나오는 건 메모리 구조를 절약하기 위해서! 왜냐하면 List.of()는 필드 기반 구현이 있고, 내부적으로 힙 공간을 덜 사용하기에 요소 자체가 필요하다면 List.of()가 적절하기 때문이라고 함!


출처

영준님이 주신 자바의 메모리 구조 링크

Memory Layout of Objects in Java

List.of() method란?

비밀을 풀어보자!




출처

출처

참고) Arrays.asList()와 List.of()의 비교


출처

비밀 푸는데 도움이 되셨으면 좋겠습니다...!!!
덕분에 찾아보면서 공부 많이 됐어요ㅎㅎ

@Jiyeong-github Jiyeong-github added the 👍 Additional 추가로 공부하고 공유한 내용입니다. label Dec 1, 2022
@Jiyeong-github Jiyeong-github changed the title [item 53] 영준님이 궁금해 하셨던 List.of()의 비밀 파헤치🗝️ [item 53] 영준님이 궁금해 하셨던 List.of()의 비밀 파헤치기🗝️ Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👍 Additional 추가로 공부하고 공유한 내용입니다.
Projects
None yet
Development

No branches or pull requests

1 participant