Why are the parameters float and double lambda limited to the set value of the float, set to a double value?

Reading the Java language specification, Java SE 8 Edition, I saw something interesting in §15.27.1 lambda parameters:

A lambda type parameter floatalways contains an element of a set of float values ​​(§4.2.3); likewise, a lambda type parameter doublealways contains a double value element. A type lambda parameter is not allowed to floatcontain 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 doubleto 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 floateither doubleto 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 " strictfplambda 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 floatand doublelambda to be inside a set floating point value or double value respectively?

+4
1

JSR-335, B "- float":

8.4.1 " ".

, §8.4.1 , :

float float (§4.2.3); , double . , float float-extended-exponent, float double , .

JLS 2 , .

, .

+2

Source: https://habr.com/ru/post/1692465/


All Articles