我正在尝试在方法开始时测试空输入。如果发现是真的,我想返回 null,即使该方法通常会返回 double 值。
我需要将方法的类型保持为double
public double computeMean (double[] grades) {
if (grades == null) {
return null;
Cannot convert from null to double
最佳答案
你应该使用
Double
wrapper class(mind the uppercase "d")
如果您希望能够返回 null
,则不要将 double
原始类型作为您的返回类型。
关于java - 在返回 double java的方法中返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58453232/