Why mixing + and cast does not produce an error in “+(int)+(long)-1”?

You are not adding nor substracting. Those + and – operators are unary sign operators.

See documentation at The Unary Operators section.

The sequence at stake:

(byte)+(short)-(int)+(long)-1

is evaluated from right to left like this:

the initial value is -1
casting to long (which is still -1)
unary + sign (still -1)
casting to int (still -1)
unary – sign (now the value is 1)
so on (the value remains 1 until the end)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)