我对Function.identity()方法的使用有疑问。
想象以下代码:
Arrays.asList("a", "b", "c")
          .stream()
          .map(Function.identity()) // <- This,
          .map(str -> str)          // <- is the same as this.
          .collect(Collectors.toMap(
                       Function.identity(), // <-- And this,
                       str -> str));        // <-- is the same as this.
是否有任何理由您应使用Function.identity()代替str->str(反之亦然)。我认为第二个选项更具可读性(当然是个人喜好了)。但是,有没有“真正的”理由为什么应该优先考虑呢?
t -> t仅仅因为它更简洁。