woowacourse / tecoble-comments

0 stars 0 forks source link

tecoble/post/2020-05-14-foreach-vs-forloop/ #8

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Stream의 foreach 와 for-loop 는 다르다. | javable

Stream에 대한 기본적인 학습을 위해 찾아왔다면, 공식 오라클 문서를 참고하면 좋을 것 같다. (java8 부터는 Stream과 Lambda를 제공한다.) 자바에서 Stream은 컬렉션 등의 요소를 하나씩 참조해 함수형 인터페이스(람다식)를 통해 반복적인 작업의 처리를 가능하게 해준다. Stream이 반복

https://woowacourse.github.io/tecoble/post/2020-05-14-foreach-vs-forloop/

hojinDev commented 4 years ago

잘봤습니다.

내용과는 무관하지만 예제에 있는 Objects.isNull(names) 은 2가지 문제점이 있습니다.

  1. names ㄱㅏ null 인지만 판단합니다. CollectionUtils.isEmpty 를 사용하길 권장합니다.
  2. javaDoc 을보면 아래와 같이 써있습니다.
    @apiNote This method exists to be used as a
     * {@link java.util.function.Predicate}, {@code filter(Objects::isNull)}

    용도 자체가 if 문에 사용하는게 아니라는것이죠. 실제

    
    if (Objects.isNull(target) {
    }

if (null == target) { }


두개 중에 가독성은 null == 이게 더 뛰어납니다.
YerinCho commented 4 years ago

좋은 지적 정말 감사합니다! 덕분에 몰랐던 사실을 저도 배우게 되네요 :)