posted 16 years ago
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!