class CollectorUtils {
private CollectorUtils() {
}
public static <T> Collector<T, ?, T> onlyElement() {
return Collectors.collectingAndThen(Collectors.toList(), Iterables::getOnlyElement);
}
public static <T> Collector<T, ?, Optional<T>> optionalElement() {
return Collectors.collectingAndThen(Collectors.toList(), (list) -> {
return Optional.ofNullable(Iterables.getOnlyElement(list, (Object)null));
});
}
public static <T> Collector<T, ?, List<T>> toList() {
return Collectors.toCollection(ArrayList::new);
}
}
我得到推理变量 T 的边界不兼容。
java:不兼容的类型:推理变量 T 具有不兼容的边界等式约束:T 下界:T,java.lang.Object,T