
.collect(Collectors.toCollection(LinkedHashSet::new)) // java.util.LinkedHashSet#LinkedHashSet() // java.util.LinkedHashSet#LinkedHashSet(int) 如果想让它走#LinkedHashSet(int),有什么简写方式吗?
// 其实就是问这一坨的简写,不要纠结为何要这么写,我就是举个例子来研究研究 .collect(Collectors.toCollection(new Supplier<LinkedHashSet<Object>>() { @Override public LinkedHashSet<Object> get() { return new LinkedHashSet<>(3); } })); 1 kawowa 2020 年 9 月 26 日 查了下,collectors 没有 toLinkedList 之类的,内容里面的::new 就是简写了吧 |
2 lxk11153 OP @kawowa #1 你理解不对,我是说`(LinkedHashSet::new))`调用的是`#LinkedHashSet()`方法, 我想问 ?如何简写? 让它调用的是`#LinkedHashSet(int)`方法 [doge] |
3 wowo243 2020 年 9 月 26 日 via Android 先 maptoint ? |
5 hodur 2020 年 9 月 26 日 ::new 应该不支持带参数的 |
6 MingYueQingFeng 2020 年 9 月 26 日 LinkedHashSet::new 只是简化 HashSet hs = LinkedHashSet();用途,指定构造函数只能 .collect(Collectors.toCollection(() -> new LinkedHashSet(1))) |
8 aguesuka 2020 年 9 月 26 日 via Android 你这段代码写出来会有警告,alt 回车会变成 6 楼的形状 |