3
次のコードはコンパイルできない理由を私は理解していない:Collectors.averagingDoubleで二重配列の平均を計算するには?
import java.util.Arrays;
import java.util.stream.Collectors;
public class AppMain {
public static void main(String args[]) {
double[] x = {5.4, 5.56, 1.0};
double avg = Arrays.stream(x).collect(Collectors.averagingDouble(n -> n));
}
}
エラーメッセージは全く不明です。
The method collect(Supplier<R>, ObjDoubleConsumer<R>, BiConsumer<R,R>) in the type DoubleStream is not applicable for the arguments (Collector<Object,?,Double>)
Type mismatch: cannot convert from Collector<Object,capture#1-of ?,Double> to Supplier<R>
Type mismatch: cannot convert from Object to double