Comment

Comment by sitta

> 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.
parent sitta 3 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton