Strange casting compilation error

I noticed something rather strange while working in my IDE.

double x1 = 0, x2 = 0;
int a = (int) x1 = (int) x2;

So this is an invalid syntax, unsurprisingly. However, this is an explanation of why this is an invalid syntax that confuses me. When I put this code in the Eclipse Luna and hover over the second line, a message appears saying:

Type mismatch: cannot convert from boolean to int

1 quick fix:

Change type 'a' to 'boolean'

If I ignore the error and continue to work anyway, even the Throwable stack trace shows the same message:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        Type mismatch: cannot convert from boolean to int
        Syntax error on token "=", <= expected

, , (int) x1 = (int) x2 - - , true false. - , ?

+4
1

, . - x1, :

...
cast x1 to integer
assign (int) x2 to the value of (int) x1
...

2 , (int) x1 lvalue (sry ++, , java).

+3

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


All Articles