Hi,
int i=10;
// Following need explicit cast in order to get compiled.
char c=i; byte b=i; short s=i;
//But Following works fine - compiles well.
char c=10; byte b=10; short s=10;
Well, try this
final int i=10;
char c=i;byte=i;short=i;
All these assignments work well coz some optimization done by the compilier( Im not very sure what they mean by optimization, but u should be aware abt this behaviour). So it seems that if u assign a final value or a final variable it will work fine.
Another thing - in a mockexam (
http://valiveru.tripod.com/java/jvaltest.html) the following declaration is said valid. (which I tested does NOT compile)
int i=10; char c=i;
It will work but with a cast.
Anything wrong?
Thanks
Sanjeet
[This message has been edited by Sanjeet Karamchandani (edited August 19, 2000).]