java - Strange Compilation Error Involving Casting -


i noticed rather strange when working in ide.

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

so invalid syntax, unsurprisingly. however, it's explanation of why it's invalid syntax confuses me. when put code in eclipse luna , hover on second line, message appears says:

type mismatch: cannot convert boolean int

1 quick fix available:

change type of 'a' 'boolean'

if ignore error , proceed run anyway, throwable stack trace shows same message:

exception in thread "main" java.lang.error: unresolved compilation problems:          type mismatch: cannot convert boolean int         syntax error on token "=", <= expected 

i don't understand why compiler thinks (int) x1 = (int) x2 sort of comparison evaluates true or false. have idea of why so?

the castoperator has higher priority assignment operators. due this, can't assign cast value x1, since compiler interprets as:

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

step 2 won't work, since (int) x1 no lvalue (sry using term c++, have no idea if there exists synonym in java).


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -