Reading the Java language specification, Java SE 8 Edition, I saw something interesting in §15.27.1 lambda parameters:
A lambda type parameter float
always contains an element of a set of float values (§4.2.3); likewise, a lambda type parameter double
always contains a double value element. A type lambda parameter is not allowed to float
contain a value set element with the extension float-extended-exponent, which is also not an element of the float value set, or for a type lambda parameter double
to contain a value element with a double expanded exponent, which is not also a set element double values.
This seems to mean that the virtual machine will first display the expanded precision value float
either double
to a (non-expanded) floating point value or a double value set by converting the set of values before the lambda expression or lambda body is evaluated. However, the specification no longer requires that the lambda estimate be strictly FP, and it does not seem possible to make a " strictfp
lambda expression / body".
I suppose this means that the following two statements are not strictly equivalent:
doubleStream.map((operand) -> operand + 2.);
doubleStream.map(new DoubleUnaryOperator() {
@Override
public double applyAsDouble(double operand) {
return operand + 2.;
}
});
Is it correct?
What is the reason that JLS requires parameter values float
and double
lambda to be inside a set floating point value or double value respectively?