.collect(Collectors.toCollection(LinkedHashSet::new))
// java.util.LinkedHashSet#LinkedHashSet()
// java.util.LinkedHashSet#LinkedHashSet(int)
如果想让它走#LinkedHashSet(int),有什么简写方式吗?
.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);
}
}));
|
kawowaSep 26, 2020
1
查了下,collectors 没有 toLinkedList 之类的,内容里面的::new 就是简写了吧
|
|
2
@kawowa #1 你理解不对,我是说`(LinkedHashSet::new))`调用的是`#LinkedHashSet()`方法,
我想问 ?如何简写? 让它调用的是`#LinkedHashSet(int)`方法 [doge] |
|
wowo243Sep 26, 2020 via Android
3
先 maptoint ?
|
|
hodurSep 26, 2020
5
::new 应该不支持带参数的
|
|
6
LinkedHashSet::new 只是简化 HashSet hs = LinkedHashSet();用途,指定构造函数只能 .collect(Collectors.toCollection(() -> new LinkedHashSet(1)))
|
|
aguesukaSep 26, 2020 via Android
8
你这段代码写出来会有警告,alt 回车会变成 6 楼的形状
|