top | item 37801027

(no title)

sitta | 2 years ago

> Having to use streams in order to use map, etc., is noisy. Why weren't these APIs retrofitted to collections?

Sure, methods along the lines of the following could have been added:

  public <R> List<R> map(Function<? super E, ? extends R> mapper) {
      return stream().map(mapper).toList();
  }
Yes, having them would make Java less verbose in the case where you only want to do a single map, filter, whatever operation on a collection, but I'm personally glad that they weren't because they produce extremely inefficient behavior when chained. So, it would add a performance footgun to save ~18 characters.

discuss

order

No comments yet.