If I understand right, in the above code, a copy of the value of c in Line 1 is copied into the final variable c in the method parameter in Line 2. If Line 3 is uncommented, the compiler complains that c is a final variable. However when I return c (In line 4), the implicit narrowing conversion from a 'compile time constant char' to a byte, does not happen. Why ?
Originally posted by Jerry Zhang: From char to any of byte or short, and vice verse, you need explicit cast
Well that is not entirely accurate. See the following code
The compiler does an implicit cast if the RHS is a compile time constant.
- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Joined: May 15, 2004
Vicken, thanks. jerry
Joined: Jul 10, 2003
Originally posted by Barry Gaunt: The compiler does not know that every character c passed into the method m1 is going to fit in to a byte. So it gives the "possible loss of precision" error.
But in the case of
the compiler does not worry that every character c may not fit into a byte? Am I the only one who feels that the behaviour was not very intiutive Oh well, I'll just remember the scenario for the exam...
Joined: Jul 21, 2003
Originally posted by V Bose:
the compiler does not worry that every character c may not fit into a byte?
Yes, that is correct, because 'c' is a compile time constant.