比较用于将双精度数添加到双精度数的两个运算符类型:DoubleUnaryOperator和UnaryOperator<Double>:
public void test() {
double doub = 10.0;
// This is OK
DoubleUnaryOperator oo = d -> {
return doub + d;
};
// Compilation error: Local variable doub defined in an enclosing scope must be final or effectively final
UnaryOperator<Double> o = d -> {
return doub + d;
};
doub = oo.applyAsDouble(.3);
doub = o.apply(.3);
}
为什么只有UnaryOperator<Double>才会出现编译错误(doub不是最终的)?如果变量声明从未改变,为什么会出现不同的结果?
www说
12345678_0001
相关分类