Sent from float to double

Can someone explain to me why this code does not compile:

boolean r = (boolean) 0;

Why is this compiling?

double z = (float) 2.0_0+0___2;

I do not understand the alphabet in which the numbers after the float are written.

+4
source share
2 answers

The first one does not compile because you simply cannot assign a number boolean. A boolean- trueor false.

, , 2_000_000 . , float (a double, float double ).

, , , . , 2.00+02, double octal 02. - 2+2, 0___10, z = 10. float, , 64 32 , 64 . , .

+9

, PHP Javascript 0, , false, boolean, false. C, 0 false. . Java boolean. truey-ish, , :

public class LooselyTyped {
    public boolean toBoolean(int input) {
        return input != 0;
    }

    public boolean toBoolean(Object input) {
        return (input != null) && (!input.equals(""));
    }
}

:

boolean lt = LooselyTyped.toBoolean(yourvariable);
0

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


All Articles