.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-09-26 08:24:50 +08:00 查了下,collectors 没有 toLinkedList 之类的,内容里面的::new 就是简写了吧 |
![]() | 2 lxk11153 OP @kawowa #1 你理解不对,我是说`(LinkedHashSet::new))`调用的是`#LinkedHashSet()`方法, 我想问 ?如何简写? 让它调用的是`#LinkedHashSet(int)`方法 [doge] |
![]() | 3 wowo243 2020-09-26 08:44:42 +08:00 via Android 先 maptoint ? |
5 hodur 2020-09-26 09:05:25 +08:00 ::new 应该不支持带参数的 |
![]() | 6 MingYueQingFeng 2020-09-26 09:13:31 +08:00 ![]() LinkedHashSet::new 只是简化 HashSet hs = LinkedHashSet();用途,指定构造函数只能 .collect(Collectors.toCollection(() -> new LinkedHashSet(1))) |
8 aguesuka 2020-09-26 09:33:37 +08:00 via Android 你这段代码写出来会有警告,alt 回车会变成 6 楼的形状 |