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

[Chapter 5] limit(1) 이 있는데도 findFirst() 가 있는 이유 #10

Open
BUYA-GH opened this issue Oct 26, 2022 · 0 comments
Open

Comments

@BUYA-GH
Copy link
Contributor

BUYA-GH commented Oct 26, 2022

출처

출처는 없습니다.

질문

findFirst() 는 filter 조건에 일치하는 element 1개를 Optional로 리턴하는 함수입니다.

그런데 제가 생각하기에는 limit(1) 과 역할의 차이가 있는지 궁금합니다.

물론 findFirst()는 Optional로 리턴하기 때문에 null 오류를 방지할 수 있는 이점이 있지만
limit(1) 에서도 충분히 개발자가 빈 array에 관한 예외는 처리할 수 있다고 생각합니다.

제가 알지 못하는 둘의 차이점이 있을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant