Why Java 8 Stream interface does not have min() no-parameter version?

前端 未结 4 1685
难免孤独
难免孤独 2020-12-31 06:55

java.util.stream.Stream interface has two versions of sorted method – sorted() which sorts elements in natural order and sorted(

4条回答
  •  旧巷少年郎
    2020-12-31 07:45

    I'd assume that would just pollute the API. one could say "why is there no max parameterless version", "why is there no CharStream" and it could on and on in terms of the things that could be made available but were decided best not to.

    having a parameterless min method over this:

    someList.stream().min(Comparator.naturalOrder());
    

    would be no different.

    therefore it's best to just create a reusable method rather than polluting the API with all the possible things.

提交回复
热议问题