It will difinitely give you an compile error since your assigning a value which in int type to a variable which has byte type.. But of course, you can explicitly cast it (e.g byte b = (byte)i; ) but the precise value will be lost.. The value will be squeeze to byte and disregard the rest which will not be fitted to the size of byte(8 bits)
Rizwan, This sure will give you possible loss of precision error.But if you initialize final int i where you declared it, will compile fine.Because the compiler sees that 127 will surely fit in a byte and its value is not going to change since it is final. But, if you just say int i=127 or anything <127 ,the compiler cannot be sure if that value is going to be same.So it flags an error eventhough the value fits comfortably in a byte. Another thing,this holds true only if the value is <=127.If the value is above the range of byte,even if it is a comile time constant ,compiler flags an error.Hope this clears!
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
how do I do my own kindle-like thing - without amazon