【发布时间】:2018-01-24 02:03:23
【问题描述】:
我对 Collectors.toList() 和 Collectors.toSet() 静态方法感到很困惑。这两种方法不接受任何参数。那么他们怎么知道要返回什么类型的 Collector 呢?
例如,如果我们有这行:
Collectors.toList();
返回的收集器是Collector<Object,?,List<Object>>。
如果我们有这一行:
Collector<Integer,?,List<Integer>> c = Collectors.toList();
然后 Collectors.toList() 将返回一个Collector<Integer,?,List<Integer>>。在不接受任何输入参数的情况下,toList() 方法如何知道它需要返回一个Collector<Integer,?,List<Integer>>?
也许如何编写 toList() 的示例代码将有助于我的理解。
提前致谢。
【问题讨论】: