我有一个看起来像这样的方法。
public void some(..., Collection<? super Some> collection) {
// WOOT, PECS!!!
final Stream<Some> stream = getStream();
stream.collect(toCollection(() -> collection));
}
以及如何使此方法安全地返回给定的集合实例类型?
我试过这个。
public <T extends Collection<? super Some>> T some(..., T collection) {
final Stream<Some> stream = getStream();
stream.collect(toCollection(() -> collection)); // error.
return collection; // this is what I want to do
}