Originally posted by Tresa P Anthony:
Hi,
Could you please explain the following?
On compilation, i get a compile time error only at line 1 but not at line 2 as i had expected. Please explain why compiler okays line 2.
I am using jdk 1.4.
Thanks
[ August 15, 2006: Message edited by: Tresa P Anthony ]
You cannot assign an int which is not a compile-time constant in the range of byte into a byte without an explicit cast.
In the second line, it only matters that the type of the expression is int.
The compiler does not carry out any calculations. It is only checking type in this case.
Originally posted by Keith Lynn:
The compiler is not doing any computations.
The problem is not that 127 + 1 is outside the range of byte. The problem is that the type of the sum is int.
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Vlado Zajac
The error on first line is caused by trying to assign int to byte
Don't get me started about those stupid light bulbs. |